Skip to content

Commit

Permalink
Strict mode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Aug 10, 2021
1 parent a52cffe commit 26cd3b9
Showing 1 changed file with 59 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
import { RenderTest, test, jitSuite, syntaxErrorFor } from '../..';
import { RenderTest, test, jitSuite, syntaxErrorFor, defineComponent, trackedObj } from '../..';

class LessThanTest extends RenderTest {
static suiteName = '{{lt}} keyword';

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

this.assertHTML('false');
}

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

this.assertHTML('false');
}

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

this.assertHTML('true');
}

@test
['correctly resolves when values update eq']() {
this.render(`{{lt this.foo this.bar}}`, { foo: 123, bar: 456 });
let args = trackedObj({ foo: 123, bar: 456 });
const AComponent = defineComponent({}, '{{lt @foo @bar}}');
this.renderComponent(AComponent, args);

this.assertHTML('true');

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

this.assertHTML('false');

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

this.assertHTML('false');
Expand All @@ -42,7 +49,8 @@ class LessThanTest extends RenderTest {
@test
['it errors']() {
this.assert.throws(() => {
this.render(`{{lt 1 2 1}}`);
const AComponent = defineComponent({}, '{{lt 1 2 1}}');
this.renderComponent(AComponent);
}, syntaxErrorFor('(lt) can receive a maximum of 2 arguments', '{{lt 1 2 1}}', 'an unknown module', 1, 0));
}
}
Expand All @@ -52,44 +60,52 @@ class LessThanEqualTest extends RenderTest {

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

this.assertHTML('true');
}

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

this.assertHTML('true');
}

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

this.assertHTML('false');
}

@test
['correctly resolves when values update neq']() {
this.render(`{{lte this.foo this.bar}}`, { foo: 123, bar: 456 });
let args = trackedObj({ foo: 123, bar: 456 });
const AComponent = defineComponent({}, '{{lte @foo @bar}}');
this.renderComponent(AComponent, args);

this.assertHTML('true');

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

this.assertHTML('true');

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

this.assertHTML('false');
}

@test
['it errors']() {
this.assert.throws(() => {
this.render(`{{lte 1 2 1}}`);
const AComponent = defineComponent({}, '{{lte 1 2 1}}');
this.renderComponent(AComponent);
}, syntaxErrorFor('(lte) can receive a maximum of 2 arguments', '{{lte 1 2 1}}', 'an unknown module', 1, 0));
}
}
Expand All @@ -102,44 +118,52 @@ class GreaterThanTest extends RenderTest {

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

this.assertHTML('false');
}

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

this.assertHTML('false');
}

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

this.assertHTML('true');
}

@test
['correctly resolves when values update eq']() {
this.render(`{{gt this.foo this.bar}}`, { foo: 123, bar: 456 });
let args = trackedObj({ foo: 123, bar: 456 });
const AComponent = defineComponent({}, '{{gt @foo @bar}}');
this.renderComponent(AComponent, args);

this.assertHTML('false');

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

this.assertHTML('false');

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

this.assertHTML('true');
}

@test
['it errors']() {
this.assert.throws(() => {
this.render(`{{gt 1 2 1}}`);
const AComponent = defineComponent({}, '{{gt 1 2 1}}');
this.renderComponent(AComponent);
}, syntaxErrorFor('(gt) can receive a maximum of 2 arguments', '{{gt 1 2 1}}', 'an unknown module', 1, 0));
}
}
Expand All @@ -149,44 +173,52 @@ class GreaterThanEqualTest extends RenderTest {

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

this.assertHTML('true');
}

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

this.assertHTML('true');
}

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

this.assertHTML('false');
}

@test
['correctly resolves when values update neq']() {
this.render(`{{gte this.foo this.bar}}`, { foo: 123, bar: 456 });
let args = trackedObj({ foo: 123, bar: 456 });
const AComponent = defineComponent({}, '{{gte @foo @bar}}');
this.renderComponent(AComponent, args);

this.assertHTML('false');

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

this.assertHTML('true');

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

this.assertHTML('true');
}

@test
['it errors']() {
this.assert.throws(() => {
this.render(`{{gte 1 2 1}}`);
const AComponent = defineComponent({}, '{{gte 1 2 1}}');
this.renderComponent(AComponent);
}, syntaxErrorFor('(gte) can receive a maximum of 2 arguments', '{{gte 1 2 1}}', 'an unknown module', 1, 0));
}
}
Expand Down

0 comments on commit 26cd3b9

Please sign in to comment.