test: support Promise as return value in `inject`

This commit is contained in:
Maciej Barelkowski 2021-05-17 09:32:49 +02:00 committed by fake-join[bot]
parent 065bff5655
commit 789e03afe6
2 changed files with 67 additions and 1 deletions

View File

@ -226,7 +226,7 @@ export function inject(fn) {
);
}
BPMN_JS.invoke(fn);
return BPMN_JS.invoke(fn);
};
}

View File

@ -0,0 +1,66 @@
import {
bootstrapModeler,
inject
} from 'test/TestHelper';
import coreModule from 'lib/core';
import { expect } from 'chai';
describe('helper - inject', function() {
var diagramXML = require('../../fixtures/bpmn/simple.bpmn');
beforeEach(bootstrapModeler(diagramXML, {
modules: [
coreModule
]
}));
it('should work with Promise as return value', function() {
// given
var expected = 'resolved';
// when
var test = inject(function(eventBus) {
expect(eventBus).to.exist;
return Promise.resolve(expected);
});
// then
return test().then(function(result) {
expect(result).to.eql(expected);
});
});
it('should handle Promise rejection', function() {
// given
var expected = new Error('rejected');
function onResolved() {
throw new Error('should not resolve');
}
function onRejected(error) {
expect(error).to.eql(expected);
}
// when
var test = inject(function(eventBus) {
expect(eventBus).to.exist;
return Promise.reject(expected);
});
// then
return test().then(onResolved, onRejected);
});
});