vendredi 9 septembre 2016

Assert inside of a stub/mock ember service during acceptance/integration tests

In unit tests for a service, I have been putting asserts inside of service stubs, which has come in rather handy.

unit-test.js

let fooServiceStub = Ember.Object.extend({
    fooMethod(bar) {
        this.assert.ok(bar, 'fooMethod called with bar');
    }
});

...

test('blah', function(assert) {
    assert.expect(1);
    let stubFooService = fooServiceStub.create({ assert });
    let fooService = this.subject({
        fooService: stubFooService
    });

    fooService.fooMethod('data');
});

Is an assert inside of a stub service possible for an acceptance/integration test?

The issue that I am running into is that for acceptance/integration tests, the way the service is injected is different from unit tests.

acceptance-test.js

let fooServiceStub = Ember.Service.extend({
    fooMethod(bar) {
        return 'baz';
    }
});

....

beforeEach: function () {
    this.register('service:foo-service', fooServiceStub);
    // Calling inject puts the service instance in the test's context,
    // making it accessible as "locationService" within each test
    this.inject.service('foo-service', { as: 'fooService' });
}

I have not found a way to pass in the 'assert' object into such a stub.

To me, this is desirable to do during an acceptance test. The service goes off and does stuff that would be rather complicated to mock in the acceptance test, and I don't want to re-test my service. I just want to confirm the expected service calls were triggered.




Aucun commentaire:

Enregistrer un commentaire