I’m working in a project that is largely untested, unfortunately we have some instances of markup that appears to require refactoring in order to be testable.
For example, when the HTML contains value.bind
or class.bind
or checked.bind
the test fails, an example of value.bind
error below.
import { ComponentTester, StageComponent } from "aurelia-testing";
import { bootstrap } from "aurelia-bootstrapper";
import { PLATFORM } from "aurelia-pal";
import * as path from "path";
import { Options } from "aurelia-loader-nodejs";
Options.relativeToDir = path.join(__dirname);
describe("MyComponent", () => {
let component: ComponentTester;
beforeEach(() => {
component = StageComponent.withResources(
PLATFORM.moduleName("./component")
).inView("<component></component>")
.boundTo({ value: "foo" });
});
it("should render", (done) => {
component
.create(bootstrap)
.then(() => {
const element = document.querySelector(".bar");
expect(element).toBeTruthy();
done();
})
.catch((e) => {
console.log(e.toString());
});
});
The View
<template>
<input type='input' value.bind='value' class="bar" />
</template>
Error: The value property of a object ([object HTMLInputElement]) cannot be assigned.
Is there a workaround to using value.bind
? I’ve seen code examples on discourse using value.bind
, so maybe there is something particular about the configuration of our tests.