Testing a class with a snap field in Aurelia

Say I have a class like this:

import {bindable} from 'aurelia-framework';
export default class MyClass {
    @bindable text = null;
    bind() {
        this.message = `Message: ${this.text}`;
    }
}

And in my test code, I have the following code:

import MyClass from '../../src/myclass';

describe('MyClass', () => {

    let sut;
    beforeEach(() => sut = new MyClass());

    describe('bind', () => {

        beforeEach(() => {
            sut.text = "my text";
            sut.bind();
        });

        it('should have a message', () => {
            expect(sut.message).toBe('Message: my text');
        });

    });

});

When I run this test, I raise the following error:

TypeError: Cannot read the 'getOrCreateObserversLookup' property from undefined at getObserver (C: / Users / vinte / Documents / projects / mealcal / jspm_packages / github / aurelia / templating@0.15.1 /aurelia-templating.js: 2571: 40) on MyClass.descriptor.set [as text] (C: / Users / vinte / Documents / projects / mealcal / jspm_packages / github / aurelia / templating@0.15.1 /aurelia-templating.js: 2628: 9) in the object. (C: /Users/vinte/Documents/projects/mealcal/test/unit/myclass.spec.js: 26: 16)

, , , bindable.

?

+4
1

@bindable , templating.

.

  it('should raise value change on simple custom element', done => {
    var ele = BehaviorInstance.createForUnitTest(SimpleElement);
    spyOn(ele, 'fooChanged');
    spyOn(ele, 'barChanged');

    ele.foo = 'new foo';
    ele.bar = 'new bar';

    setTimeout(() => {
      expect(ele.fooChanged).toHaveBeenCalledWith('new foo', 'foo');
      expect(ele.barChanged).toHaveBeenCalledWith('new bar', 'bar');
      done();
    });
  });

, . , bindable, valueChanged. , , , , .

+6

Source: https://habr.com/ru/post/1606307/


All Articles