Skip to content

Testing a custom attributes' valueChanged() hook #70

@MarcScheib

Description

@MarcScheib

I'm submitting a bug report

  • Library Version:
    ^1.0.0-beta.3.0.1

Please tell us about your environment:

  • Operating System:
    Windows 10

  • Node Version:
    8.1.3

  • NPM Version:
    5.0.3

  • JSPM OR Webpack AND Version
    JSPM 0.16.53

  • Browser:
    Chrome

  • Language:
    ESNext

Current behavior:

When testing a custom attribute with one bound value and valueChanged() method, the method is not called during the spec, although the value binding is working in e.g. an input field.

  • What is the expected behavior?

The valueChanged() is called during testing when changing the bound value.

  • What is the motivation / use case for changing the behavior?

Testing the logic of a custom attributes valueChanged() hook.

I am using the following code so far and binding is also working for the input, but not for the custom attribute:

import {bootstrap} from 'aurelia-bootstrapper';
import {Aurelia} from 'aurelia-framework';
import {StageComponent} from 'aurelia-testing';
import {DOM} from 'aurelia-pal';

import {BackgroundChanger} from '../../src/background-changer';

describe('BackgroundChange', () => {
  let component;
  let vm = { bg: 'blue' };

  beforeEach(() => {
    component = StageComponent
      .withResources('src/background-changer')
      .inView(`
<input id="bg-input" value.bind="bg">
<div id="bg" bg-change.bind="code"></div>
`)
      .boundTo(vm);
  });

  afterEach(() => {
    component.dispose();
  });

  it('changes the background on input change', done => {
    component.create(bootstrap)
      .then(() => {
        const inputEl = DOM.getElementById('bg-input');
        const divEl = DOM.getElementById('bg');

        expect(inputEl.value).toEqual(vm.bg);

        const newBg = 'red';

        inputEl.value = newBg;
        expect(inputEl.value).toEqual(newBg);
        inputEl.dispatchEvent(DOM.createCustomEvent('change'));
        expect(vm.bg).toEqual(newBg);
        expect(divEl.style.background).toEqual(newBg); // this one fails with expected blue to be red
      })
      .then(done);
  });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions