mirror of
https://github.com/sartography/bpmn-js.git
synced 2025-01-11 17:44:12 +00:00
test: support Promise as return value in inject
This commit is contained in:
parent
065bff5655
commit
789e03afe6
@ -226,7 +226,7 @@ export function inject(fn) {
|
||||
);
|
||||
}
|
||||
|
||||
BPMN_JS.invoke(fn);
|
||||
return BPMN_JS.invoke(fn);
|
||||
};
|
||||
}
|
||||
|
||||
|
66
test/spec/helper/InjectSpec.js
Normal file
66
test/spec/helper/InjectSpec.js
Normal 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);
|
||||
});
|
||||
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user