From 26cd3b9fa3e9150db3d3cc1f22165d690fa5576c Mon Sep 17 00:00:00 2001 From: scott-newcomer Date: Wed, 14 Apr 2021 18:56:34 -0500 Subject: [PATCH] Strict mode tests --- .../test/keywords/comparison-test.ts | 86 +++++++++++++------ 1 file changed, 59 insertions(+), 27 deletions(-) diff --git a/packages/@glimmer/integration-tests/test/keywords/comparison-test.ts b/packages/@glimmer/integration-tests/test/keywords/comparison-test.ts index 2b942eacd2..8029514712 100644 --- a/packages/@glimmer/integration-tests/test/keywords/comparison-test.ts +++ b/packages/@glimmer/integration-tests/test/keywords/comparison-test.ts @@ -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'); @@ -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)); } } @@ -52,36 +60,43 @@ 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'); } @@ -89,7 +104,8 @@ class LessThanEqualTest extends RenderTest { @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)); } } @@ -102,36 +118,43 @@ 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'); } @@ -139,7 +162,8 @@ class GreaterThanTest extends RenderTest { @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)); } } @@ -149,36 +173,43 @@ 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'); } @@ -186,7 +217,8 @@ class GreaterThanEqualTest extends RenderTest { @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)); } }