Update test specs to use Jasmine 3 (#2089)

* Updated Karma and Jasmine versions

* Added DOMObserver class. Supports promise-based testing of DOM changes

Update asynchronous test specs to use promises or done() instead of waitsFor/runs

* Modified ActionCapability to duplicate context object properties as own properties for better object equality comparisons

* Global find + replace to fix syntax issues

* Fixed various issues caused by non-deterministic runtime order of tests in Jasmine 3. Fixed issues caused by changes to determination of object equality

* Addressed review comments

* Resolved merge conflicts with master

* Fixed style errors

* Use spy.calls.count() instead of manually tracking
This commit is contained in:
Andrew Henry
2018-06-29 17:32:59 -07:00
committed by Pete Richards
parent 013eba744d
commit 433dee0314
305 changed files with 2866 additions and 3324 deletions

View File

@@ -39,7 +39,7 @@ define(
testPath = "/test/path";
testInterval = 12321; // Some number
mockHttp.get.andReturn(mockPromise);
mockHttp.get.and.returnValue(mockPromise);
indicator = new ElasticIndicator(
mockHttp,
@@ -73,7 +73,7 @@ define(
// Nominal just means getting back an object, without
// an error field.
mockPromise.then.mostRecentCall.args[0]({ data: {} });
mockPromise.then.calls.mostRecent().args[0]({ data: {} });
// Verify that these values changed;
// don't test for specific text.
@@ -92,7 +92,7 @@ define(
// Nominal just means getting back an object, without
// an error field.
mockPromise.then.mostRecentCall.args[1]({ data: {} });
mockPromise.then.calls.mostRecent().args[1]({ data: {} });
// Verify that these values changed;
// don't test for specific text.

View File

@@ -46,8 +46,8 @@ define(
mockHttp = jasmine.createSpy("$http");
mockQ = jasmine.createSpyObj("$q", ["when", "reject"]);
mockQ.when.andCallFake(mockPromise);
mockQ.reject.andCallFake(function (value) {
mockQ.when.and.callFake(mockPromise);
mockQ.reject.and.callFake(function (value) {
return {
then: function (ignored, callback) {
return mockPromise(callback(value));
@@ -84,27 +84,30 @@ define(
it("allows object creation", function () {
var model = { someKey: "some value" };
mockHttp.andReturn(mockPromise({
mockHttp.and.returnValue(mockPromise({
data: { "_id": "abc", "_version": 1 }
}));
provider.createObject("testSpace", "abc", model).then(capture);
expect(mockHttp).toHaveBeenCalledWith({
url: "/test/db/abc",
method: "PUT",
data: model
data: model,
params: undefined
});
expect(capture.mostRecentCall.args[0]).toBeTruthy();
expect(capture.calls.mostRecent().args[0]).toBeTruthy();
});
it("allows object models to be read back", function () {
var model = { someKey: "some value" };
mockHttp.andReturn(mockPromise({
mockHttp.and.returnValue(mockPromise({
data: { "_id": "abc", "_version": 1, "_source": model }
}));
provider.readObject("testSpace", "abc").then(capture);
expect(mockHttp).toHaveBeenCalledWith({
url: "/test/db/abc",
method: "GET"
method: "GET",
params: undefined,
data: undefined
});
expect(capture).toHaveBeenCalledWith(model);
});
@@ -113,13 +116,13 @@ define(
var model = { someKey: "some value" };
// First do a read to populate rev tags...
mockHttp.andReturn(mockPromise({
mockHttp.and.returnValue(mockPromise({
data: { "_id": "abc", "_version": 42, "_source": {} }
}));
provider.readObject("testSpace", "abc");
// Now perform an update
mockHttp.andReturn(mockPromise({
mockHttp.and.returnValue(mockPromise({
data: { "_id": "abc", "_version": 43, "_source": {} }
}));
provider.updateObject("testSpace", "abc", model).then(capture);
@@ -129,31 +132,33 @@ define(
params: { version: 42 },
data: model
});
expect(capture.mostRecentCall.args[0]).toBeTruthy();
expect(capture.calls.mostRecent().args[0]).toBeTruthy();
});
it("allows object deletion", function () {
// First do a read to populate rev tags...
mockHttp.andReturn(mockPromise({
mockHttp.and.returnValue(mockPromise({
data: { "_id": "abc", "_version": 42, "_source": {} }
}));
provider.readObject("testSpace", "abc");
// Now perform an update
mockHttp.andReturn(mockPromise({
mockHttp.and.returnValue(mockPromise({
data: { "_id": "abc", "_version": 42, "_source": {} }
}));
provider.deleteObject("testSpace", "abc", {}).then(capture);
expect(mockHttp).toHaveBeenCalledWith({
url: "/test/db/abc",
method: "DELETE"
method: "DELETE",
params: undefined,
data: undefined
});
expect(capture.mostRecentCall.args[0]).toBeTruthy();
expect(capture.calls.mostRecent().args[0]).toBeTruthy();
});
it("returns undefined when objects are not found", function () {
// Act like a 404
mockHttp.andReturn({
mockHttp.and.returnValue({
then: function (success, fail) {
return mockPromise(fail());
}
@@ -167,13 +172,13 @@ define(
mockErrorCallback = jasmine.createSpy('error');
// First do a read to populate rev tags...
mockHttp.andReturn(mockPromise({
mockHttp.and.returnValue(mockPromise({
data: { "_id": "abc", "_version": 42, "_source": {} }
}));
provider.readObject("testSpace", "abc");
// Now perform an update
mockHttp.andReturn(mockPromise({
mockHttp.and.returnValue(mockPromise({
data: { "status": 409, "error": "Revision error..." }
}));
provider.updateObject("testSpace", "abc", model).then(
@@ -190,13 +195,13 @@ define(
mockErrorCallback = jasmine.createSpy('error');
// First do a read to populate rev tags...
mockHttp.andReturn(mockPromise({
mockHttp.and.returnValue(mockPromise({
data: { "_id": "abc", "_version": 42, "_source": {} }
}));
provider.readObject("testSpace", "abc");
// Now perform an update
mockHttp.andReturn(mockPromise({
mockHttp.and.returnValue(mockPromise({
data: { "status": 410, "error": "Revision error..." }
}));
provider.updateObject("testSpace", "abc", model).then(

View File

@@ -43,10 +43,10 @@ define([
describe('query', function () {
beforeEach(function () {
spyOn(provider, 'cleanTerm').andReturn('cleanedTerm');
spyOn(provider, 'fuzzyMatchUnquotedTerms').andReturn('fuzzy');
spyOn(provider, 'parseResponse').andReturn('parsedResponse');
$http.andReturn(Promise.resolve({}));
spyOn(provider, 'cleanTerm').and.returnValue('cleanedTerm');
spyOn(provider, 'fuzzyMatchUnquotedTerms').and.returnValue('fuzzy');
spyOn(provider, 'parseResponse').and.returnValue('parsedResponse');
$http.and.returnValue(Promise.resolve({}));
});
it('cleans terms and adds fuzzyness', function () {
@@ -69,40 +69,28 @@ define([
});
it('gracefully fails when http fails', function () {
var promiseChainResolved = false;
$http.andReturn(Promise.reject());
$http.and.returnValue(Promise.reject());
provider
return provider
.query('hello', 10)
.then(function (results) {
expect(results).toEqual({
hits: [],
total: 0
});
promiseChainResolved = true;
});
waitsFor(function () {
return promiseChainResolved;
});
});
it('parses and returns when http succeeds', function () {
var promiseChainResolved = false;
$http.andReturn(Promise.resolve('successResponse'));
$http.and.returnValue(Promise.resolve('successResponse'));
provider
return provider
.query('hello', 10)
.then(function (results) {
expect(provider.parseResponse)
.toHaveBeenCalledWith('successResponse');
expect(results).toBe('parsedResponse');
promiseChainResolved = true;
});
waitsFor(function () {
return promiseChainResolved;
});
});
});