add prettier and eslint
This commit is contained in:
@@ -1,22 +1,30 @@
|
||||
describe('AsyncExpectation', function() {
|
||||
beforeEach(function() {
|
||||
jasmineUnderTest.Expectation.addAsyncCoreMatchers(jasmineUnderTest.asyncMatchers);
|
||||
jasmineUnderTest.Expectation.addAsyncCoreMatchers(
|
||||
jasmineUnderTest.asyncMatchers
|
||||
);
|
||||
});
|
||||
|
||||
describe('Factory', function() {
|
||||
it('throws an Error if promises are not available', function() {
|
||||
var thenable = {then: function() {}},
|
||||
options = {global: {}, actual: thenable}
|
||||
function f() { jasmineUnderTest.Expectation.asyncFactory(options); }
|
||||
expect(f).toThrowError('expectAsync is unavailable because the environment does not support promises.');
|
||||
var thenable = { then: function() {} },
|
||||
options = { global: {}, actual: thenable };
|
||||
function f() {
|
||||
jasmineUnderTest.Expectation.asyncFactory(options);
|
||||
}
|
||||
expect(f).toThrowError(
|
||||
'expectAsync is unavailable because the environment does not support promises.'
|
||||
);
|
||||
});
|
||||
|
||||
it('throws an Error if the argument is not a promise', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
function f() {
|
||||
jasmineUnderTest.Expectation.asyncFactory({actual: 'not a promise'});
|
||||
jasmineUnderTest.Expectation.asyncFactory({ actual: 'not a promise' });
|
||||
}
|
||||
expect(f).toThrowError('Expected expectAsync to be called with a promise.');
|
||||
expect(f).toThrowError(
|
||||
'Expected expectAsync to be called with a promise.'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -33,7 +41,8 @@ describe('AsyncExpectation', function() {
|
||||
});
|
||||
|
||||
return expectation.not.toBeResolved().then(function() {
|
||||
expect(addExpectationResult).toHaveBeenCalledWith(false,
|
||||
expect(addExpectationResult).toHaveBeenCalledWith(
|
||||
false,
|
||||
jasmine.objectContaining({
|
||||
passed: false,
|
||||
message: 'Expected a promise not to be resolved.'
|
||||
@@ -54,7 +63,8 @@ describe('AsyncExpectation', function() {
|
||||
});
|
||||
|
||||
return expectation.not.toBeResolved().then(function() {
|
||||
expect(addExpectationResult).toHaveBeenCalledWith(true,
|
||||
expect(addExpectationResult).toHaveBeenCalledWith(
|
||||
true,
|
||||
jasmine.objectContaining({
|
||||
passed: true,
|
||||
message: ''
|
||||
@@ -68,7 +78,6 @@ describe('AsyncExpectation', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
var error = new Error('ExpectationSpec failure');
|
||||
|
||||
|
||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = dummyPromise(),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
@@ -76,22 +85,26 @@ describe('AsyncExpectation', function() {
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
|
||||
spyOn(expectation, 'toBeResolved')
|
||||
.and.returnValue(Promise.reject(error));
|
||||
spyOn(expectation, 'toBeResolved').and.returnValue(Promise.reject(error));
|
||||
|
||||
return expectation.toBeResolved()
|
||||
.then(
|
||||
function() { fail('Expected a rejection'); },
|
||||
function(e) { expect(e).toBe(error); }
|
||||
);
|
||||
return expectation.toBeResolved().then(
|
||||
function() {
|
||||
fail('Expected a rejection');
|
||||
},
|
||||
function(e) {
|
||||
expect(e).toBe(error);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('#withContext', function() {
|
||||
it("prepends the context to the generated failure message", function() {
|
||||
it('prepends the context to the generated failure message', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var util = {
|
||||
buildFailureMessage: function() { return 'failure message'; }
|
||||
buildFailureMessage: function() {
|
||||
return 'failure message';
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
@@ -100,21 +113,26 @@ describe('AsyncExpectation', function() {
|
||||
util: util
|
||||
});
|
||||
|
||||
return expectation.withContext('Some context').toBeResolved()
|
||||
.then(
|
||||
function() {
|
||||
expect(addExpectationResult).toHaveBeenCalledWith(false,
|
||||
jasmine.objectContaining({
|
||||
message: 'Some context: failure message'
|
||||
}));
|
||||
});
|
||||
return expectation
|
||||
.withContext('Some context')
|
||||
.toBeResolved()
|
||||
.then(function() {
|
||||
expect(addExpectationResult).toHaveBeenCalledWith(
|
||||
false,
|
||||
jasmine.objectContaining({
|
||||
message: 'Some context: failure message'
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("prepends the context to a custom failure message", function() {
|
||||
it('prepends the context to a custom failure message', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var util = {
|
||||
buildFailureMessage: function() { return 'failure message'; }
|
||||
buildFailureMessage: function() {
|
||||
return 'failure message';
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
@@ -123,22 +141,28 @@ describe('AsyncExpectation', function() {
|
||||
util: util
|
||||
});
|
||||
|
||||
return expectation.withContext('Some context').toBeResolvedTo('a')
|
||||
.then(
|
||||
function() {
|
||||
expect(addExpectationResult).toHaveBeenCalledWith(false,
|
||||
jasmine.objectContaining({
|
||||
message: "Some context: Expected a promise to be resolved to 'a' but it was rejected."
|
||||
}));
|
||||
});
|
||||
return expectation
|
||||
.withContext('Some context')
|
||||
.toBeResolvedTo('a')
|
||||
.then(function() {
|
||||
expect(addExpectationResult).toHaveBeenCalledWith(
|
||||
false,
|
||||
jasmine.objectContaining({
|
||||
message:
|
||||
"Some context: Expected a promise to be resolved to 'a' but it was rejected."
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("prepends the context to a custom failure message from a function", function() {
|
||||
it('prepends the context to a custom failure message from a function', function() {
|
||||
pending('should actually work, but no custom matchers for async yet');
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var util = {
|
||||
buildFailureMessage: function() { return 'failure message'; }
|
||||
buildFailureMessage: function() {
|
||||
return 'failure message';
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = Promise.reject(),
|
||||
@@ -148,17 +172,20 @@ describe('AsyncExpectation', function() {
|
||||
util: util
|
||||
});
|
||||
|
||||
return expectation.withContext('Some context').toBeResolved()
|
||||
.then(
|
||||
function() {
|
||||
expect(addExpectationResult).toHaveBeenCalledWith(false,
|
||||
jasmine.objectContaining({
|
||||
message: 'Some context: msg'
|
||||
}));
|
||||
});
|
||||
return expectation
|
||||
.withContext('Some context')
|
||||
.toBeResolved()
|
||||
.then(function() {
|
||||
expect(addExpectationResult).toHaveBeenCalledWith(
|
||||
false,
|
||||
jasmine.objectContaining({
|
||||
message: 'Some context: msg'
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("works with #not", function() {
|
||||
it('works with #not', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
@@ -169,17 +196,20 @@ describe('AsyncExpectation', function() {
|
||||
util: jasmineUnderTest.matchersUtil
|
||||
});
|
||||
|
||||
return expectation.withContext('Some context').not.toBeResolved()
|
||||
.then(
|
||||
function() {
|
||||
expect(addExpectationResult).toHaveBeenCalledWith(false,
|
||||
jasmine.objectContaining({
|
||||
message: 'Some context: Expected a promise not to be resolved.'
|
||||
}));
|
||||
});
|
||||
return expectation
|
||||
.withContext('Some context')
|
||||
.not.toBeResolved()
|
||||
.then(function() {
|
||||
expect(addExpectationResult).toHaveBeenCalledWith(
|
||||
false,
|
||||
jasmine.objectContaining({
|
||||
message: 'Some context: Expected a promise not to be resolved.'
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("works with #not and a custom message", function() {
|
||||
it('works with #not and a custom message', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
@@ -190,19 +220,22 @@ describe('AsyncExpectation', function() {
|
||||
util: jasmineUnderTest.matchersUtil
|
||||
});
|
||||
|
||||
return expectation.withContext('Some context').not.toBeResolvedTo('a')
|
||||
.then(
|
||||
function() {
|
||||
expect(addExpectationResult).toHaveBeenCalledWith(false,
|
||||
jasmine.objectContaining({
|
||||
message: "Some context: Expected a promise not to be resolved to 'a'."
|
||||
}));
|
||||
});
|
||||
return expectation
|
||||
.withContext('Some context')
|
||||
.not.toBeResolvedTo('a')
|
||||
.then(function() {
|
||||
expect(addExpectationResult).toHaveBeenCalledWith(
|
||||
false,
|
||||
jasmine.objectContaining({
|
||||
message:
|
||||
"Some context: Expected a promise not to be resolved to 'a'."
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function dummyPromise() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
});
|
||||
return new Promise(function(resolve, reject) {});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user