Ember & Cypress | Integration test failing likely due to lack of store context
I am working with Ember.js on the frontend and using Cypress.io for integration testing. I have a "Order Status" button that upon click is supposed to use data within the store to access the specific order and navigate to the Order Status page.
However within the test, upon click from the modal, the Order Status page cannot load and my test throws this error:
TypeError: Cannot read property ‘_internalModel’ of null
...in the console, which I think likely has to do with that route's model not finding the order from within the store and loading.
In the Cypress test, I've created the necessary routes to pass in session data, but am struggling to understand if the lack of store data is throwing this error, and how to fix it. It is important to note that this whole flow works 100% on its own - I'm just trying to get test coverage.
I'll attach snippets from the relevant files / functions below -- please do let me know if more information is needed. I really suspect that Cypress cannot access the Ember store, but after much research and experimenting, I'm not exactly sure what the issue is.
order-status.js - model function from route
async model({ order_id: orderId }) {
let cachedOrder = this.get('store').peekRecord('order', orderId);
return cachedOrder
? cachedOrder
: await this.get('store').findRecord('order', orderId);
},
modal.hbs - where we navigate from current page to order-status route
<fieldset>
<span class="modal-text">See order status</span>
<div class="inline-button-wrap">
<button
{{action 'decline'}}
class="close-btn button-hollow-green">
Close
</button>
<button
{{action 'accept'}}
class="order-status-btn">
Order Status
</button>
</div>
</fieldset>
test.js - test that simulates clicking order status button above
it('order status btn navigates to order status page', () => {
cy.server();
cy.route('GET', '/api/session', sessionResponse);
cy.route('GET', `/api/orders/*`, order);
cy.visit('/');
cy.get('.delivery-card .button-cta').click(); //opens modal
cy.get('#modal .order-status-btn').click(); //navigates to order-status
});
Thanks so much for your help.
ember.js integration-testing cypress
add a comment |
I am working with Ember.js on the frontend and using Cypress.io for integration testing. I have a "Order Status" button that upon click is supposed to use data within the store to access the specific order and navigate to the Order Status page.
However within the test, upon click from the modal, the Order Status page cannot load and my test throws this error:
TypeError: Cannot read property ‘_internalModel’ of null
...in the console, which I think likely has to do with that route's model not finding the order from within the store and loading.
In the Cypress test, I've created the necessary routes to pass in session data, but am struggling to understand if the lack of store data is throwing this error, and how to fix it. It is important to note that this whole flow works 100% on its own - I'm just trying to get test coverage.
I'll attach snippets from the relevant files / functions below -- please do let me know if more information is needed. I really suspect that Cypress cannot access the Ember store, but after much research and experimenting, I'm not exactly sure what the issue is.
order-status.js - model function from route
async model({ order_id: orderId }) {
let cachedOrder = this.get('store').peekRecord('order', orderId);
return cachedOrder
? cachedOrder
: await this.get('store').findRecord('order', orderId);
},
modal.hbs - where we navigate from current page to order-status route
<fieldset>
<span class="modal-text">See order status</span>
<div class="inline-button-wrap">
<button
{{action 'decline'}}
class="close-btn button-hollow-green">
Close
</button>
<button
{{action 'accept'}}
class="order-status-btn">
Order Status
</button>
</div>
</fieldset>
test.js - test that simulates clicking order status button above
it('order status btn navigates to order status page', () => {
cy.server();
cy.route('GET', '/api/session', sessionResponse);
cy.route('GET', `/api/orders/*`, order);
cy.visit('/');
cy.get('.delivery-card .button-cta').click(); //opens modal
cy.get('#modal .order-status-btn').click(); //navigates to order-status
});
Thanks so much for your help.
ember.js integration-testing cypress
1
In the Cypress test, I've created the necessary routes to pass in session data - if you are expectingcy.route('GET', '/api/session', sessionResponse)
to supply data to the app (as the above line indicates) then you should usecy.request()
instead.
– eric99
Nov 22 '18 at 9:46
add a comment |
I am working with Ember.js on the frontend and using Cypress.io for integration testing. I have a "Order Status" button that upon click is supposed to use data within the store to access the specific order and navigate to the Order Status page.
However within the test, upon click from the modal, the Order Status page cannot load and my test throws this error:
TypeError: Cannot read property ‘_internalModel’ of null
...in the console, which I think likely has to do with that route's model not finding the order from within the store and loading.
In the Cypress test, I've created the necessary routes to pass in session data, but am struggling to understand if the lack of store data is throwing this error, and how to fix it. It is important to note that this whole flow works 100% on its own - I'm just trying to get test coverage.
I'll attach snippets from the relevant files / functions below -- please do let me know if more information is needed. I really suspect that Cypress cannot access the Ember store, but after much research and experimenting, I'm not exactly sure what the issue is.
order-status.js - model function from route
async model({ order_id: orderId }) {
let cachedOrder = this.get('store').peekRecord('order', orderId);
return cachedOrder
? cachedOrder
: await this.get('store').findRecord('order', orderId);
},
modal.hbs - where we navigate from current page to order-status route
<fieldset>
<span class="modal-text">See order status</span>
<div class="inline-button-wrap">
<button
{{action 'decline'}}
class="close-btn button-hollow-green">
Close
</button>
<button
{{action 'accept'}}
class="order-status-btn">
Order Status
</button>
</div>
</fieldset>
test.js - test that simulates clicking order status button above
it('order status btn navigates to order status page', () => {
cy.server();
cy.route('GET', '/api/session', sessionResponse);
cy.route('GET', `/api/orders/*`, order);
cy.visit('/');
cy.get('.delivery-card .button-cta').click(); //opens modal
cy.get('#modal .order-status-btn').click(); //navigates to order-status
});
Thanks so much for your help.
ember.js integration-testing cypress
I am working with Ember.js on the frontend and using Cypress.io for integration testing. I have a "Order Status" button that upon click is supposed to use data within the store to access the specific order and navigate to the Order Status page.
However within the test, upon click from the modal, the Order Status page cannot load and my test throws this error:
TypeError: Cannot read property ‘_internalModel’ of null
...in the console, which I think likely has to do with that route's model not finding the order from within the store and loading.
In the Cypress test, I've created the necessary routes to pass in session data, but am struggling to understand if the lack of store data is throwing this error, and how to fix it. It is important to note that this whole flow works 100% on its own - I'm just trying to get test coverage.
I'll attach snippets from the relevant files / functions below -- please do let me know if more information is needed. I really suspect that Cypress cannot access the Ember store, but after much research and experimenting, I'm not exactly sure what the issue is.
order-status.js - model function from route
async model({ order_id: orderId }) {
let cachedOrder = this.get('store').peekRecord('order', orderId);
return cachedOrder
? cachedOrder
: await this.get('store').findRecord('order', orderId);
},
modal.hbs - where we navigate from current page to order-status route
<fieldset>
<span class="modal-text">See order status</span>
<div class="inline-button-wrap">
<button
{{action 'decline'}}
class="close-btn button-hollow-green">
Close
</button>
<button
{{action 'accept'}}
class="order-status-btn">
Order Status
</button>
</div>
</fieldset>
test.js - test that simulates clicking order status button above
it('order status btn navigates to order status page', () => {
cy.server();
cy.route('GET', '/api/session', sessionResponse);
cy.route('GET', `/api/orders/*`, order);
cy.visit('/');
cy.get('.delivery-card .button-cta').click(); //opens modal
cy.get('#modal .order-status-btn').click(); //navigates to order-status
});
Thanks so much for your help.
ember.js integration-testing cypress
ember.js integration-testing cypress
edited Jan 3 at 18:42
jacefarm
2,87932638
2,87932638
asked Nov 22 '18 at 0:33
hasaabhasaab
202
202
1
In the Cypress test, I've created the necessary routes to pass in session data - if you are expectingcy.route('GET', '/api/session', sessionResponse)
to supply data to the app (as the above line indicates) then you should usecy.request()
instead.
– eric99
Nov 22 '18 at 9:46
add a comment |
1
In the Cypress test, I've created the necessary routes to pass in session data - if you are expectingcy.route('GET', '/api/session', sessionResponse)
to supply data to the app (as the above line indicates) then you should usecy.request()
instead.
– eric99
Nov 22 '18 at 9:46
1
1
In the Cypress test, I've created the necessary routes to pass in session data - if you are expecting
cy.route('GET', '/api/session', sessionResponse)
to supply data to the app (as the above line indicates) then you should use cy.request()
instead.– eric99
Nov 22 '18 at 9:46
In the Cypress test, I've created the necessary routes to pass in session data - if you are expecting
cy.route('GET', '/api/session', sessionResponse)
to supply data to the app (as the above line indicates) then you should use cy.request()
instead.– eric99
Nov 22 '18 at 9:46
add a comment |
1 Answer
1
active
oldest
votes
Whether stubbing API requests or not, Ember's store should behave as expected when used in conjunction with Cypress. The error mentioned is a good clue to the primary problem – an undefined model. It's not fully clear how your application is working while the Cypress test is failing and throwing an error, but a couple of changes (some in Ember, some in Cypress) should clear things up. Here's a breakdown for resolving this issue (some reverse engineering / assumptions made, from the code examples provided)...
Send along the order id
via the button action that opens the modal (in the delivery-card HTML mark-up):
<button class="button-cta" {{action 'openModal' order.id}}>
Open Order Status Modal
</button>
The openModal
action passes along the order id
as a param for the model
on the subsequent modal route, when transitioning. In the delivery-card.js controller:
actions: {
openModal(id) {
this.transitionToRoute('modal', id); // <-- id
}
}
Then, the modal's accept
action passes along the id
to the order status page as well, when transitioning. In the modal.js controller:
actions: {
accept() {
this.transitionToRoute('order-status', this.get('model.id')); // <-- here
},
decline() {
...
Further, in order-status.js, the argument passed to the model hook can be simplified as params
:
async model(params) { // <-- just use params
const id = params.id; // <-- id
const cachedOrder = this.get('store').peekRecord('order', id); // <-- id
return cachedOrder
? cachedOrder
: await this.get('store').findRecord('order', id); // <-- id
}
Finally, some changes to test.js:
it('order status btn navigates to order status page', () => {
cy.server();
cy.route('GET', `/api/session`, 'fixture:session.json'); // <-- here
cy.route('GET', `/api/orders`, 'fixture:orders.json'); // <-- here
cy.visit('/');
cy.get('.delivery-card .button-cta').click(); // opens modal
cy.get('#modal .order-status-btn').click(); // navigates to order-status
// here, verify that an order status is displayed
cy.get('.current-status')
.should(($el) => {
const statusTextValue = $el[0].innerText;
expect(statusTextValue).to.not.be.empty;
});
});
The API GET
requests are stubbed with fixtures using standard Cypress conventions.
Finally, here's a screenshot of the Cypress runner, showing only the initial XHR STUB
request when GET-ting orders
. Notice that Ember's store methods, peekRecord
and findRecord
, used in the order-status.js route file, do not generate any further XHR requests, and, result in no errors being thrown. Ember's store is functioning as anticipated.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422339%2fember-cypress-integration-test-failing-likely-due-to-lack-of-store-context%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Whether stubbing API requests or not, Ember's store should behave as expected when used in conjunction with Cypress. The error mentioned is a good clue to the primary problem – an undefined model. It's not fully clear how your application is working while the Cypress test is failing and throwing an error, but a couple of changes (some in Ember, some in Cypress) should clear things up. Here's a breakdown for resolving this issue (some reverse engineering / assumptions made, from the code examples provided)...
Send along the order id
via the button action that opens the modal (in the delivery-card HTML mark-up):
<button class="button-cta" {{action 'openModal' order.id}}>
Open Order Status Modal
</button>
The openModal
action passes along the order id
as a param for the model
on the subsequent modal route, when transitioning. In the delivery-card.js controller:
actions: {
openModal(id) {
this.transitionToRoute('modal', id); // <-- id
}
}
Then, the modal's accept
action passes along the id
to the order status page as well, when transitioning. In the modal.js controller:
actions: {
accept() {
this.transitionToRoute('order-status', this.get('model.id')); // <-- here
},
decline() {
...
Further, in order-status.js, the argument passed to the model hook can be simplified as params
:
async model(params) { // <-- just use params
const id = params.id; // <-- id
const cachedOrder = this.get('store').peekRecord('order', id); // <-- id
return cachedOrder
? cachedOrder
: await this.get('store').findRecord('order', id); // <-- id
}
Finally, some changes to test.js:
it('order status btn navigates to order status page', () => {
cy.server();
cy.route('GET', `/api/session`, 'fixture:session.json'); // <-- here
cy.route('GET', `/api/orders`, 'fixture:orders.json'); // <-- here
cy.visit('/');
cy.get('.delivery-card .button-cta').click(); // opens modal
cy.get('#modal .order-status-btn').click(); // navigates to order-status
// here, verify that an order status is displayed
cy.get('.current-status')
.should(($el) => {
const statusTextValue = $el[0].innerText;
expect(statusTextValue).to.not.be.empty;
});
});
The API GET
requests are stubbed with fixtures using standard Cypress conventions.
Finally, here's a screenshot of the Cypress runner, showing only the initial XHR STUB
request when GET-ting orders
. Notice that Ember's store methods, peekRecord
and findRecord
, used in the order-status.js route file, do not generate any further XHR requests, and, result in no errors being thrown. Ember's store is functioning as anticipated.
add a comment |
Whether stubbing API requests or not, Ember's store should behave as expected when used in conjunction with Cypress. The error mentioned is a good clue to the primary problem – an undefined model. It's not fully clear how your application is working while the Cypress test is failing and throwing an error, but a couple of changes (some in Ember, some in Cypress) should clear things up. Here's a breakdown for resolving this issue (some reverse engineering / assumptions made, from the code examples provided)...
Send along the order id
via the button action that opens the modal (in the delivery-card HTML mark-up):
<button class="button-cta" {{action 'openModal' order.id}}>
Open Order Status Modal
</button>
The openModal
action passes along the order id
as a param for the model
on the subsequent modal route, when transitioning. In the delivery-card.js controller:
actions: {
openModal(id) {
this.transitionToRoute('modal', id); // <-- id
}
}
Then, the modal's accept
action passes along the id
to the order status page as well, when transitioning. In the modal.js controller:
actions: {
accept() {
this.transitionToRoute('order-status', this.get('model.id')); // <-- here
},
decline() {
...
Further, in order-status.js, the argument passed to the model hook can be simplified as params
:
async model(params) { // <-- just use params
const id = params.id; // <-- id
const cachedOrder = this.get('store').peekRecord('order', id); // <-- id
return cachedOrder
? cachedOrder
: await this.get('store').findRecord('order', id); // <-- id
}
Finally, some changes to test.js:
it('order status btn navigates to order status page', () => {
cy.server();
cy.route('GET', `/api/session`, 'fixture:session.json'); // <-- here
cy.route('GET', `/api/orders`, 'fixture:orders.json'); // <-- here
cy.visit('/');
cy.get('.delivery-card .button-cta').click(); // opens modal
cy.get('#modal .order-status-btn').click(); // navigates to order-status
// here, verify that an order status is displayed
cy.get('.current-status')
.should(($el) => {
const statusTextValue = $el[0].innerText;
expect(statusTextValue).to.not.be.empty;
});
});
The API GET
requests are stubbed with fixtures using standard Cypress conventions.
Finally, here's a screenshot of the Cypress runner, showing only the initial XHR STUB
request when GET-ting orders
. Notice that Ember's store methods, peekRecord
and findRecord
, used in the order-status.js route file, do not generate any further XHR requests, and, result in no errors being thrown. Ember's store is functioning as anticipated.
add a comment |
Whether stubbing API requests or not, Ember's store should behave as expected when used in conjunction with Cypress. The error mentioned is a good clue to the primary problem – an undefined model. It's not fully clear how your application is working while the Cypress test is failing and throwing an error, but a couple of changes (some in Ember, some in Cypress) should clear things up. Here's a breakdown for resolving this issue (some reverse engineering / assumptions made, from the code examples provided)...
Send along the order id
via the button action that opens the modal (in the delivery-card HTML mark-up):
<button class="button-cta" {{action 'openModal' order.id}}>
Open Order Status Modal
</button>
The openModal
action passes along the order id
as a param for the model
on the subsequent modal route, when transitioning. In the delivery-card.js controller:
actions: {
openModal(id) {
this.transitionToRoute('modal', id); // <-- id
}
}
Then, the modal's accept
action passes along the id
to the order status page as well, when transitioning. In the modal.js controller:
actions: {
accept() {
this.transitionToRoute('order-status', this.get('model.id')); // <-- here
},
decline() {
...
Further, in order-status.js, the argument passed to the model hook can be simplified as params
:
async model(params) { // <-- just use params
const id = params.id; // <-- id
const cachedOrder = this.get('store').peekRecord('order', id); // <-- id
return cachedOrder
? cachedOrder
: await this.get('store').findRecord('order', id); // <-- id
}
Finally, some changes to test.js:
it('order status btn navigates to order status page', () => {
cy.server();
cy.route('GET', `/api/session`, 'fixture:session.json'); // <-- here
cy.route('GET', `/api/orders`, 'fixture:orders.json'); // <-- here
cy.visit('/');
cy.get('.delivery-card .button-cta').click(); // opens modal
cy.get('#modal .order-status-btn').click(); // navigates to order-status
// here, verify that an order status is displayed
cy.get('.current-status')
.should(($el) => {
const statusTextValue = $el[0].innerText;
expect(statusTextValue).to.not.be.empty;
});
});
The API GET
requests are stubbed with fixtures using standard Cypress conventions.
Finally, here's a screenshot of the Cypress runner, showing only the initial XHR STUB
request when GET-ting orders
. Notice that Ember's store methods, peekRecord
and findRecord
, used in the order-status.js route file, do not generate any further XHR requests, and, result in no errors being thrown. Ember's store is functioning as anticipated.
Whether stubbing API requests or not, Ember's store should behave as expected when used in conjunction with Cypress. The error mentioned is a good clue to the primary problem – an undefined model. It's not fully clear how your application is working while the Cypress test is failing and throwing an error, but a couple of changes (some in Ember, some in Cypress) should clear things up. Here's a breakdown for resolving this issue (some reverse engineering / assumptions made, from the code examples provided)...
Send along the order id
via the button action that opens the modal (in the delivery-card HTML mark-up):
<button class="button-cta" {{action 'openModal' order.id}}>
Open Order Status Modal
</button>
The openModal
action passes along the order id
as a param for the model
on the subsequent modal route, when transitioning. In the delivery-card.js controller:
actions: {
openModal(id) {
this.transitionToRoute('modal', id); // <-- id
}
}
Then, the modal's accept
action passes along the id
to the order status page as well, when transitioning. In the modal.js controller:
actions: {
accept() {
this.transitionToRoute('order-status', this.get('model.id')); // <-- here
},
decline() {
...
Further, in order-status.js, the argument passed to the model hook can be simplified as params
:
async model(params) { // <-- just use params
const id = params.id; // <-- id
const cachedOrder = this.get('store').peekRecord('order', id); // <-- id
return cachedOrder
? cachedOrder
: await this.get('store').findRecord('order', id); // <-- id
}
Finally, some changes to test.js:
it('order status btn navigates to order status page', () => {
cy.server();
cy.route('GET', `/api/session`, 'fixture:session.json'); // <-- here
cy.route('GET', `/api/orders`, 'fixture:orders.json'); // <-- here
cy.visit('/');
cy.get('.delivery-card .button-cta').click(); // opens modal
cy.get('#modal .order-status-btn').click(); // navigates to order-status
// here, verify that an order status is displayed
cy.get('.current-status')
.should(($el) => {
const statusTextValue = $el[0].innerText;
expect(statusTextValue).to.not.be.empty;
});
});
The API GET
requests are stubbed with fixtures using standard Cypress conventions.
Finally, here's a screenshot of the Cypress runner, showing only the initial XHR STUB
request when GET-ting orders
. Notice that Ember's store methods, peekRecord
and findRecord
, used in the order-status.js route file, do not generate any further XHR requests, and, result in no errors being thrown. Ember's store is functioning as anticipated.
edited Jan 8 at 11:56
answered Jan 7 at 22:04
jacefarmjacefarm
2,87932638
2,87932638
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422339%2fember-cypress-integration-test-failing-likely-due-to-lack-of-store-context%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
In the Cypress test, I've created the necessary routes to pass in session data - if you are expecting
cy.route('GET', '/api/session', sessionResponse)
to supply data to the app (as the above line indicates) then you should usecy.request()
instead.– eric99
Nov 22 '18 at 9:46