From 48589060a7fa5a3a906dab1244e6038d877ffa50 Mon Sep 17 00:00:00 2001 From: scott-newcomer Date: Wed, 14 Apr 2021 19:07:46 -0500 Subject: [PATCH] Strict mode tests --- .../test/keywords/logical-test.ts | 69 +++++++++++-------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/packages/@glimmer/integration-tests/test/keywords/logical-test.ts b/packages/@glimmer/integration-tests/test/keywords/logical-test.ts index 4a5114107c..db0a5c0c7d 100644 --- a/packages/@glimmer/integration-tests/test/keywords/logical-test.ts +++ b/packages/@glimmer/integration-tests/test/keywords/logical-test.ts @@ -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'); @@ -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'); } @@ -125,14 +131,16 @@ 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'); } @@ -140,7 +148,8 @@ class NotTest extends RenderTest { @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)); } }