Accessing engine service during acceptance test
See original GitHub issueWe are running an acceptance test, during which we want to stub out a method on one of the services which is included on the engine. I don’t think/I can’t find a clean way to get access to this service from the acceptance test.
Originally we tried this:
test('send view event on result page', async function(assert) {
let count = 0;
this.application.resolveRegistration('booking-flow@service:ecommerce-analytics').reopen({
reportView(folder) {
assert.ok(folder.get('cents'), 'Folder has a price');
assert.ok(folder.get('origin'), 'Folder has an origin');
assert.ok(folder.get('destination'), 'Folder has a destination');
count++;
},
});
/* some function that gets test to right state */
await goToResult.call(this, assert);
assert.equal(count, 1, 'reportView is called once');
});
The problem being here that we reopen
the class
and not the instance
of the service, so 1 test works, subsequent tests break as they have all the other stubs on them. We solved this by doing the following:
test('send view event on result page', async function(assert) {
let count = 0;
reopenEcommerceAnalytics(this, {
reportView(folder) {
assert.ok(folder.get('cents'), 'Folder has a price');
assert.ok(folder.get('origin'), 'Folder has an origin');
assert.ok(folder.get('destination'), 'Folder has a destination');
count++;
},
});
await goToResult.call(this, assert);
assert.equal(count, 1, 'reportView is called once');
});
async function reopenEcommerceAnalytics(context, hash) {
// we need to access the app so the router is instantiated and can be looked
// up below via lookup('router:main')
await visit('/');
let router = getOwner(context).lookup('router:main');
// object hash wich contains all instances of this engine, where the key is
// incremented for every new instance of this engine
let bookingFlowInstances = router._engineInstances['booking-flow'];
// since we only mounted the engine once, the current booking flow engine
// instance is always via the first (and only) key
let [instanceKey] = Object.keys(bookingFlowInstances);
let bookingFlowEngine = bookingFlowInstances[instanceKey];
let ecommerceService = bookingFlowEngine.__container__.lookup('service:ecommerce-analytics');
ecommerceService.reopen(hash);
}
Is there an easier way to get an instance of a service registered on an engine from a host app? Or a better way to test a service on an engine?
Issue Analytics
- State:
- Created 6 years ago
- Comments:8
Top Results From Across the Web
Factory Acceptance Testing - What Is FAT, and How Does It ...
A Factory Acceptance Test is a test that runs on the equipment or components before it is delivered to its intended destination. While...
Read more >What is User Acceptance Testing (UAT)? Examples - Guru99
1. One of the most important activities in the UAT is to identify and develop test scenarios. These test scenarios are derived from...
Read more >NFPA 110 Acceptance Testing - Curtis Power Solutions
NFPA 110 requires that emergency power supply systems undergo acceptance testing to confirm that the system will perform as required.
Read more >User Acceptance Testing Tools and Checklist | Quick Guide
User Acceptance Testing (UAT) tools, principles, working, and best practices for testing software systems to accept user requirements.
Read more >Site Integration Acceptance Test Procedures
III Scope of Work and tested in the San Gabriel Valley Pilot Project Acceptance ... Provides various network services that support the IEN....
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
are there any news about making this work when using new test syntax?
@lougreenwood would that help you?
and use it in a
beforeEach
hook: