Skip to content

Commit

Permalink
Strict mode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Apr 26, 2021
1 parent a23c838 commit 4858906
Showing 1 changed file with 39 additions and 30 deletions.
69 changes: 39 additions & 30 deletions packages/@glimmer/integration-tests/test/keywords/logical-test.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,60 @@
import { RenderTest, test, jitSuite, syntaxErrorFor } from '../..';
import { RenderTest, test, jitSuite, syntaxErrorFor, defineComponent, trackedObj } from '../..';

class AndTest extends RenderTest {
static suiteName = '{{and}} keyword';

@test
['it works']() {
this.render(`{{and "one" 1 true}}`);
const AComponent = defineComponent({}, '{{and "one" 1 true}}');
this.renderComponent(AComponent);

this.assertHTML('true');
}

@test
['it works falsey']() {
this.render(`{{and 1 false 2}}`);
const AComponent = defineComponent({}, '{{and 1 false 2}}');
this.renderComponent(AComponent);

this.assertHTML('false');
}

@test
['it works with one argument']() {
this.render(`{{and this.value}}`, {
value: true,
});
const AComponent = defineComponent({}, '{{and @value}}');
this.renderComponent(AComponent, { value: true });

this.assertHTML('true');
}

@test
['it works with empty arrays']() {
this.render(`{{and this.value}}`, {
value: [],
});
const AComponent = defineComponent({}, '{{and @value}}');
this.renderComponent(AComponent, { value: [] });

this.assertHTML('');
}

@test
['it works with arrays']() {
this.render(`{{and this.value}}`, {
value: [1, 2],
});
const AComponent = defineComponent({}, '{{and @value}}');
this.renderComponent(AComponent, { value: [1, 2] });

this.assertHTML('1,2');
}

@test
['it works when values update']() {
this.render(`{{and this.foo}}`, { foo: 123 });
let args = trackedObj({ foo: 123 });
const AComponent = defineComponent({}, '{{and @foo}}');
this.renderComponent(AComponent, args);

args.foo = true;
this.rerender({ foo: true });

this.assertHTML('true');

args.foo = false;
this.rerender({ foo: false });

this.assertHTML('false');
Expand All @@ -65,54 +68,57 @@ class OrTest extends RenderTest {

@test
['it works']() {
this.render(`{{or "one" 1 true}}`);
const AComponent = defineComponent({}, '{{or "one" 1 true}}');
this.renderComponent(AComponent);

this.assertHTML('one');
}

@test
['it works falsey']() {
this.render(`{{or false}}`);
const AComponent = defineComponent({}, '{{or false}}');
this.renderComponent(AComponent);

this.assertHTML('false');
}

@test
['it works with one argument']() {
this.render(`{{or this.value}}`, {
value: true,
});
const AComponent = defineComponent({}, '{{or @value}}');
this.renderComponent(AComponent, { value: true });

this.assertHTML('true');
}

@test
['it works with empty arrays']() {
this.render(`{{or this.value}}`, {
value: [],
});
const AComponent = defineComponent({}, '{{or @value}}');
this.renderComponent(AComponent, { value: [] });

this.assertHTML('');
}

@test
['it works with arrays']() {
this.render(`{{or this.value}}`, {
value: [1, 2],
});
const AComponent = defineComponent({}, '{{or @value}}');
this.renderComponent(AComponent, { value: [1, 2] });

this.assertHTML('1,2');
}

@test
['it works when values update']() {
this.render(`{{or this.foo}}`, { foo: 123 });
let args = trackedObj({ foo: 123 });
const AComponent = defineComponent({}, '{{or @foo}}');
this.renderComponent(AComponent, args);

this.rerender({ foo: true });
args.foo = true;
this.rerender(args);

this.assertHTML('true');

this.rerender({ foo: false });
args.foo = false;
this.rerender();

this.assertHTML('false');
}
Expand All @@ -125,22 +131,25 @@ class NotTest extends RenderTest {

@test
['it works']() {
this.render(`{{not 1}}`);
const AComponent = defineComponent({}, '{{not 1}}');
this.renderComponent(AComponent);

this.assertHTML('false');
}

@test
['it works falsey']() {
this.render(`{{not 0}}`);
const AComponent = defineComponent({}, '{{not 0}}');
this.renderComponent(AComponent);

this.assertHTML('true');
}

@test
['it errors with too many arguments']() {
this.assert.throws(() => {
this.render(`{{not 1 2}}`);
const AComponent = defineComponent({}, '{{not 1 2}}');
this.renderComponent(AComponent);
}, syntaxErrorFor('(not) only accepts 1 argument', '{{not 1 2}}', 'an unknown module', 1, 0));
}
}
Expand Down

0 comments on commit 4858906

Please sign in to comment.