question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Test Hooks Lack Owner Access

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rwjbluecommented, Nov 2, 2017

To directly answer the question: this.owner is setup for each test (it uses hooks.beforeEach to do this setup) which means hooks.before and hooks.after cannot access any of the properties provided by ember-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…

0reactions
rwjbluecommented, Mar 28, 2018

Recent changes made these properties read only, so you should get an error when setting them now…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found