Closed tomtomau closed 5 years ago
Bump - are things like this, shallow rendering etc going to be considered further for vNext?
In general, testing is massively improved in vNext. We've got almost 17,000 unit tests on vNext now, I believe. We've built some utiliities to enable testing things like our repeat
, compose
and if
that will probably be useful to the community. When we get a little further along, I can see us extracting those into a similar testing library for vNext. But again, testing is much simpler in general and requires much less ceremony than it does today.
Excellent, thank you for your prompt reply @EisenbergEffect! Eagerly anticipating an alpha!
@tomtomau It's failing because bindings update happens after 1 micro task flush. it should work if you do:
button.click();
await Promise.resolve();
// assert here
Thanks for replying @bigopon
That still didn't seem to work for me. I even tried explicitly flushing the queue:
https://github.com/aurelia/skeleton-navigation/commit/186aacae15f5b4a630fac6aae29aed43347b3b13
I managed to get this to work by waiting for the value to be updated, and sure enough it eventually did update within the timeout period! I think this is not failing, but I'm confused why flushing the queues didn't solve it.
I'm closing this as it was me not using it properly. Bindings updating is an async operation, so you must wait until the value updates. We use the waitFor()
methods to achieve this.
I'm submitting a bug report
Please tell us about your environment:
Operating System: OSX 10.13.4
Node Version: v8.9.3
Yarn Version: 1.3.2
Language: ESNext
Current behavior: Properties in BindingContext in a component test does not update when using twoWay binding.
In my test, I create a bindingContext with a boolean property and bind it into the component using defaultBindingMode: bindingMode.twoWay. I interact with the component and the boolean property is updated. I can inspect the property in the viewModel and it is updated, but in my test if I check the bindingContext it is not. When I test this in a browser, it works as expected.
Refer to code snippet below.
Expected/desired behavior:
I should be able to assert on the bindingContext.
See code example here or clone tomtomau/skeleton-navigation@testing-two-way-binding
What is the motivation / use case for changing the behavior?
As a developer writing a test, my expectation is to be able to assert that two-way binding is updating the property so I don't need to snoop into the component view model.