Test Hooks Lack Owner Access
See original GitHub issueI’m trying to set up easy access to a unit test’s factory, so I figured I’d so something like this:
let myFactory;
module('my test', function(hooks) {
setupTest(hooks);
hooks.before(function() {
myFactory = this.owner.factoryFor('thingy');
});
hooks.after(function() {
myFactory = undefined;
});
To my surprise, my hooks didn’t have access to this.owner
! Is this expected?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
A Complete Guide to Testing React Hooks - Toptal
This article explores how to test React Hooks and outlines an eight-step testing plan you could employ to test your own projects.
Read more >The What, Why and How of React (Testing with Hooks)
Today we're going to talk about testing in a deeper way. I will explain how to test a react application, best pattern to...
Read more >Building Your Own Hooks - React
Building your own Hooks lets you extract component logic into reusable functions ... Reducers are very convenient to test in isolation, and scale...
Read more >Hooks — Wagtail Documentation 4.1.1 documentation
Allows access to form submissions to be customised on a per-user, per-form basis. This hook takes two parameters: The user attempting to access...
Read more >Give Me a Test Hook ¿ or Else | Computerworld
But if you have ever tried to automate black box automated testing, ... when compiled into the code, give the tools access to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
To directly answer the question:
this.owner
is setup for each test (it useshooks.beforeEach
to do this setup) which meanshooks.before
andhooks.after
cannot access any of the properties provided byember-qunit
. If we moved to doing this setup once per module your tests are no longer running in isolation (they would be sharing state from prior tests) which would be quite confusing and likely to troll people…Recent changes made these properties read only, so you should get an error when setting them now…