'this' undefined from component integration test?
See original GitHub issueAlso posted on SO: https://stackoverflow.com/questions/48359509/this-undefined-only-from-component-integration-test
import Ember from 'ember';
const { Component, computed, inject: { service } } = Ember;
export default Component.extend({
currentUser: service(),
classNames: ['list-group-item'],
tagName: 'li',
visibleReagents: computed.filter('inventory.reagents', function(reagent) {
return this.get('currentUser.showArchivedReagents') || reagent.get('archivedAt');
^ undefined only in tests
})
});
This would work well ^, but not as part of the component integration tests where this would be undefined:
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import startMirage from '../../../../helpers/start-mirage';
moduleForComponent('inventories/left-menu-item', 'Integration | Component | inventories/left menu item', {
integration: true,
setup() {
startMirage(this.container);
},
afterEach() {
window.server.shutdown();
}
});
test('it renders', function(assert) {
let inventory = window.server.create('inventory', {
title: 'My inventory', createdAt: '12/01/2017'
});
inventory.reagents = window.server.createList('reagent', 15, { inventory });
this.set('inventory', inventory);
this.render(hbs`{{inventories/left-menu-item inventory=inventory}}`);
assert.equal(this.$('li').length, 1);
assert.equal(this.$('.badge').length, '1');
});
Why isn’t this accessible from the test?
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Unit Testing in Angular, Test Component is undefined
With my current code I get the error "Cannot read property 'dishForm' of undefined". So, it seems it does the DishAddComponent is not...
Read more >Testing Components depending on Services - Testing Angular
An integration test that includes a real CounterService . This guide will demonstrate both. For your Components, you need to make a decision...
Read more >Component testing scenarios - Angular
Error: This test module uses the component BannerComponent which is using a "templateUrl" or "styleUrls", but they were never compiled. Please call "TestBed....
Read more >angular test cannot read properties of undefined - You.com
The issue most likely arrises from the html file rather than the unit test or component itself. Within your html file: Go to...
Read more >React Unit Testing Using Enzyme and Jest - Toptal
In this post, we will use Jest and Enzyme to create a React.js component with basic functionality using TDD.
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 Free
Top 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

Hi, @stephanebruckert,
Your demo project adds a ton of deps, both in package.json and in bower.json. Can you try reproducing this with a brand new project (
ember new bug-reproduction) and just using Mirage (ember install ember-cli-mirage) and add the model, route, etc.?There are too many deps to track down what is happening easily.
Thanks!
Thanks @luxferresum, as you suggested it can be worked around by doing:
Not an Ember issue, maybe an ember-cli-mirage issue being discussed here https://github.com/samselikoff/ember-cli-mirage/issues/1256
Thanks everyone