How to use the @aurelia/testing.createScopeForTest function in @aurelia/testing

To help you get started, we’ve selected a few @aurelia/testing examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it('assigns defined property on bindingContext', function () {
    const scope = createScopeForTest({ foo: 'bar' });
    foo.assign(LF.none, scope, null, 'baz');
    expect(scope.bindingContext.foo).to.equal('baz');
  });
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it('does not observes property in keyed object access when key is number', function () {
    const scope = createScopeForTest({ foo: { '0': 'hello world' } });
    const expression2 = new AccessKeyed(new AccessScope('foo', 0), new PrimitiveLiteral(0));
    expect(expression2.evaluate(LF.none, scope, null)).to.equal('hello world');
    const binding = { observeProperty: spy() };
    expression2.connect(LF.none, scope, binding as any);
    expect(binding.observeProperty.getCalls()[0]).to.have.been.calledWith(LF.none, scope.bindingContext, 'foo');
    expect(binding.observeProperty.getCalls()[1]).to.have.been.calledWith(LF.none, scope.bindingContext.foo, 0);
    expect(binding.observeProperty.callCount).to.equal(2);
  });
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it(`${t1}.${t2}.evaluate() -> connect -> assign`, function () {
        const scope = createScopeForTest({ foo: obj });
        const sut = new AccessMember(new AccessScope('foo', 0), prop);
        const actual = sut.evaluate(LF.none, scope, null);
        if (canHaveProperty) {
          expect(actual).to.equal(value);
        } else {
          if (obj === null) {
            expect(actual).to.equal(null);
          } else {
            expect(actual).to.equal(undefined);
          }
        }
        const binding = { observeProperty: spy() };
        sut.connect(LF.none, scope, binding as any);
        if (canHaveProperty) {
          expect(binding.observeProperty.callCount).to.equal(2);
        } else {
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it('evaluates null/undefined object', function () {
    let scope = createScopeForTest({ foo: null });
    expect(expression.evaluate(LF.none, scope, null)).to.equal(undefined);
    scope = createScopeForTest({ foo: undefined });
    expect(expression.evaluate(LF.none, scope, null)).to.equal(undefined);
    scope = createScopeForTest({});
    expect(expression.evaluate(LF.none, scope, null)).to.equal(undefined);
  });
github aurelia / aurelia / packages / __tests__ / runtime / if.spec.ts View on Github external
it('queues the view removal via the lifecycle when the value is false', function () {
    const { attribute: ifAttr, location, lifecycle } = hydrateCustomAttribute(If as typeof If & ICustomAttributeType);

    ifAttr.value = true;
    ifAttr.$bind(LifecycleFlags.fromBind, createScopeForTest());
    runAttachLifecycle(lifecycle, ifAttr);

    const childBefore = getCurrentView(ifAttr as If);
    const prevSiblingBefore = location.previousSibling;

    ifAttr.value = false;

    let ifView = ifAttr['ifView'] as IController;
    expect(ifView).to.have.$state.isAttached();
    expect(ifView).to.have.$state.isBound();

    const childAfter = getCurrentView(ifAttr as If);
    expect(childAfter).to.equal(childBefore);
    expect(location.previousSibling).to.equal(prevSiblingBefore);
    expect(lifecycle.flushCount).to.equal(1);
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it('evaluates', function () {
    const expression = new CallMember(new AccessScope('foo', 0), 'bar', []);
    const bindingContext = { foo: { bar: () => 'baz' } };
    const scope = createScopeForTest(bindingContext);
    spy(bindingContext.foo, 'bar');
    expect(expression.evaluate(LF.none, scope, null)).to.equal('baz');
    expect((bindingContext.foo.bar as any).callCount).to.equal(1);
  });
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it(`${t1}${t2}`, function () {
          const scope = createScopeForTest({ foo: obj });
          const sut = new AccessKeyed(new AccessScope('foo', 0), key);
          const binding = { observeProperty: spy() };
          sut.connect(LF.none, scope, binding as any);
          expect(binding.observeProperty.callCount).to.equal(1);
        });
      })
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it('returns the assigned value', function () {
    const scope = createScopeForTest({ foo: { bar: 'baz' } });
    expect(expression.assign(LF.none, scope, null, 'bang')).to.equal('bang');
  });
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it(`evaluates ${expected}`, function () {
      const scope = createScopeForTest(ctx);
      expect(expr.evaluate(LF.none, scope, null)).to.equal(expected);
    });
  }
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
    expect(() => expression.evaluate(LF.mustEvaluate, createScopeForTest({ foo: { bar: null } }), null)).to.throw();
  });