Skip to content

Commit

Permalink
make expect(result).toEqual(expected) consistent throughout suites
Browse files Browse the repository at this point in the history
  • Loading branch information
sc1f authored and texodus committed Jan 2, 2019
1 parent 9c45c14 commit 2383987
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 92 deletions.
70 changes: 36 additions & 34 deletions packages/perspective/test/js/constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,14 @@ var arrow_result = [
}
];

var dt = new Date();
dt.setHours(4);
dt.setMinutes(12);
var data_4 = [{v: dt}];
var dt = () => {
let dt = new Date();
dt.setHours(4);
dt.setMinutes(12);
return dt;
};

var data_4 = [{v: dt()}];

var data_5 = [{v: "11-09-2017"}];

Expand Down Expand Up @@ -356,8 +360,8 @@ module.exports = perspective => {
var table = perspective.table(data);
var view = table.view({});
var answer = `x,y,z\r\n1,a,true\r\n2,b,false\r\n3,c,true\r\n4,d,false`;
let result2 = await view.to_csv();
expect(answer).toEqual(result2);
let result = await view.to_csv();
expect(result).toEqual(answer);
view.delete();
table.delete();
});
Expand All @@ -369,8 +373,8 @@ module.exports = perspective => {
aggregate: [{op: "sum", column: "x"}]
});
var answer = `__ROW_PATH__,x\r\n,10\r\nfalse,6\r\ntrue,4`;
let result2 = await view.to_csv();
expect(answer).toEqual(result2);
let result = await view.to_csv();
expect(result).toEqual(answer);
view.delete();
table.delete();
});
Expand All @@ -383,17 +387,17 @@ module.exports = perspective => {
aggregate: [{op: "sum", column: "x"}]
});
var answer = `__ROW_PATH__,\"a,x\",\"b,x\",\"c,x\",\"d,x\"\r\n,1,2,3,4\r\nfalse,,2,,4\r\ntrue,1,,3,`;
let result2 = await view.to_csv();
expect(answer).toEqual(result2);
let result = await view.to_csv();
expect(result).toEqual(answer);
view.delete();
table.delete();
});

it("Serializes a simple view to column-oriented JSON", async function() {
var table = perspective.table(data_3);
var view = table.view({});
let result2 = await view.to_columns();
expect(data_7).toEqual(result2);
let result = await view.to_columns();
expect(result).toEqual(data_7);
view.delete();
table.delete();
});
Expand All @@ -404,7 +408,7 @@ module.exports = perspective => {
var table = perspective.table(data);
var view = table.view();
let result = await view.to_json();
expect(data).toEqual(result);
expect(result).toEqual(data);
view.delete();
table.delete();
});
Expand All @@ -413,7 +417,7 @@ module.exports = perspective => {
var table = perspective.table(col_data);
var view = table.view();
let result = await view.to_json();
expect(data).toEqual(result);
expect(result).toEqual(data);
view.delete();
table.delete();
});
Expand All @@ -422,7 +426,7 @@ module.exports = perspective => {
var table = perspective.table(arrow.slice());
var view = table.view();
let result = await view.to_json();
expect(arrow_result).toEqual(result);
expect(result).toEqual(arrow_result);
view.delete();
table.delete();
});
Expand All @@ -440,7 +444,7 @@ module.exports = perspective => {
var table = perspective.table(csv);
var view = table.view();
let result = await view.to_json();
expect(papaparse.parse(csv, {header: true, dynamicTyping: true}).data).toEqual(result);
expect(result).toEqual(papaparse.parse(csv, {header: true, dynamicTyping: true}).data);
view.delete();
table.delete();
});
Expand All @@ -449,7 +453,7 @@ module.exports = perspective => {
var table = perspective.table(meta);
var view = table.view();
let result = await view.to_json();
expect([]).toEqual(result);
expect(result).toEqual([]);
view.delete();
table.delete();
});
Expand All @@ -458,7 +462,7 @@ module.exports = perspective => {
var table = perspective.table(data_3);
var view = table.view();
let result = await view.to_json();
expect(data_3).toEqual(result);
expect(result).toEqual(data_3);
view.delete();
table.delete();
});
Expand Down Expand Up @@ -533,14 +537,14 @@ module.exports = perspective => {
it("Handles floats schemas", async function() {
var table = perspective.table(data_3);
let result = await table.schema();
expect(meta_3).toEqual(result);
expect(result).toEqual(meta_3);
table.delete();
});

it("Generates correct date schemas", async function() {
var table = perspective.table(data_4);
let result = await table.schema();
expect(meta_4).toEqual(result);
expect(result).toEqual(meta_4);
table.delete();
});

Expand All @@ -549,25 +553,25 @@ module.exports = perspective => {
table.update(data_4);
let view = table.view();
let result = await view.to_json();
expect([{v: +data_4[0]["v"]}]).toEqual(result);
expect(result).toEqual([{v: +data_4[0]["v"]}]);
view.delete();
table.delete();
});

it("Handles datetime values", async function() {
var table = perspective.table(data_4);
let view = table.view();
let result2 = await view.to_json();
expect([{v: +data_4[0]["v"]}]).toEqual(result2);
let result = await view.to_json();
expect(result).toEqual([{v: +data_4[0]["v"]}]);
view.delete();
table.delete();
});

it("Handles datetime strings", async function() {
var table = perspective.table(data_5);
let view = table.view();
let result2 = await view.to_json();
expect([{v: +moment(data_5[0]["v"], "MM-DD-YYYY")}]).toEqual(result2);
let result = await view.to_json();
expect(result).toEqual([{v: +moment(data_5[0]["v"], "MM-DD-YYYY")}]);
view.delete();
table.delete();
});
Expand All @@ -576,13 +580,13 @@ module.exports = perspective => {
var table = perspective.table({v: "date"});
table.update(data_4);
let view = table.view();
let result2 = await view.to_json();
let result = await view.to_json();
let d = new Date(data_4[0]["v"]);
d.setHours(0);
d.setMinutes(0);
d.setSeconds(0);
d.setMilliseconds(0);
expect([{v: +d}]).toEqual(result2);
expect(result).toEqual([{v: +d}]);
view.delete();
table.delete();
});
Expand All @@ -591,7 +595,7 @@ module.exports = perspective => {
var table = perspective.table(data_6);
let view = table.view({});
let result = await view.to_json();
expect(data_6).toEqual(result);
expect(result).toEqual(data_6);
view.delete();
table.delete();
});
Expand All @@ -609,8 +613,7 @@ module.exports = perspective => {
]);
let view = table2.view({aggregate: [{op: "count", column: "const"}]});
let result = await view.to_json();
let expected = [{const: 1}, {const: 1}, {const: 1}, {const: 1}];
expect(expected).toEqual(result);
expect(result).toEqual([{const: 1}, {const: 1}, {const: 1}, {const: 1}]);
view.delete();
table2.delete();
table.delete();
Expand All @@ -629,8 +632,7 @@ module.exports = perspective => {
]);
let view = table2.view({aggregate: [{op: "count", column: "ratio"}]});
let result = await view.to_json();
let expected = [{ratio: 1.5}, {ratio: 1.25}, {ratio: 1.1666666666666667}, {ratio: 1.125}];
expect(expected).toEqual(result);
expect(result).toEqual([{ratio: 1.5}, {ratio: 1.25}, {ratio: 1.1666666666666667}, {ratio: 1.125}]);
view.delete();
table2.delete();
table.delete();
Expand Down Expand Up @@ -660,7 +662,7 @@ module.exports = perspective => {
let view = table2.view({aggregate: [{op: "count", column: "y"}, {op: "count", column: "ratio"}]});
let result = await view.to_json();
let expected = [{y: "a", ratio: 1.5}, {y: "b", ratio: 1.25}, {y: "c", ratio: 1.1666666666666667}, {y: "d", ratio: 1.125}];
expect(expected).toEqual(result);
expect(result).toEqual(expected);
view.delete();
table2.delete();
table.delete();
Expand Down Expand Up @@ -719,7 +721,7 @@ module.exports = perspective => {
}
};

expect(expected).toEqual(result);
expect(result).toEqual(expected);
table2.delete();
table.delete();
});
Expand Down
37 changes: 19 additions & 18 deletions packages/perspective/test/js/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

var yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);

var now = new Date();

var data = [{w: now, x: 1, y: "a", z: true}, {w: now, x: 2, y: "b", z: false}, {w: now, x: 3, y: "c", z: true}, {w: yesterday, x: 4, y: "d", z: false}];
Expand All @@ -35,7 +36,7 @@ module.exports = perspective => {
filter: [["x", ">", 2.0]]
});
let json = await view.to_json();
expect(rdata.slice(2)).toEqual(json);
expect(json).toEqual(rdata.slice(2));
view.delete();
table.delete();
});
Expand All @@ -46,7 +47,7 @@ module.exports = perspective => {
filter: [["x", "<", 3.0]]
});
let json = await view.to_json();
expect(rdata.slice(0, 2)).toEqual(json);
expect(json).toEqual(rdata.slice(0, 2));
view.delete();
table.delete();
});
Expand All @@ -57,7 +58,7 @@ module.exports = perspective => {
filter: [["x", ">", 4]]
});
let json = await view.to_json();
expect([]).toEqual(json);
expect(json).toEqual([]);
view.delete();
table.delete();
});
Expand All @@ -68,7 +69,7 @@ module.exports = perspective => {
filter: [["x", ">", 4]]
});
let json = await view.to_json();
expect([]).toEqual(json);
expect(json).toEqual([]);
view.delete();
table.delete();
});
Expand All @@ -81,7 +82,7 @@ module.exports = perspective => {
filter: [["x", "==", 1]]
});
let json = await view.to_json();
expect(rdata.slice(0, 1)).toEqual(json);
expect(json).toEqual(rdata.slice(0, 1));
view.delete();
table.delete();
});
Expand All @@ -92,7 +93,7 @@ module.exports = perspective => {
filter: [["x", "==", 5]]
});
let json = await view.to_json();
expect([]).toEqual(json);
expect(json).toEqual([]);
view.delete();
table.delete();
});
Expand All @@ -103,7 +104,7 @@ module.exports = perspective => {
filter: [["y", "==", "a"]]
});
let json = await view.to_json();
expect(rdata.slice(0, 1)).toEqual(json);
expect(json).toEqual(rdata.slice(0, 1));
view.delete();
table.delete();
});
Expand All @@ -114,7 +115,7 @@ module.exports = perspective => {
filter: [["y", "==", "e"]]
});
let json = await view.to_json();
expect([]).toEqual(json);
expect(json).toEqual([]);
view.delete();
table.delete();
});
Expand All @@ -125,7 +126,7 @@ module.exports = perspective => {
filter: [["z", "==", true]]
});
let json = await view.to_json();
expect([rdata[0], rdata[2]]).toEqual(json);
expect(json).toEqual([rdata[0], rdata[2]]);
view.delete();
table.delete();
});
Expand All @@ -136,7 +137,7 @@ module.exports = perspective => {
filter: [["z", "==", false]]
});
let json = await view.to_json();
expect([rdata[1], rdata[3]]).toEqual(json);
expect(json).toEqual([rdata[1], rdata[3]]);
view.delete();
table.delete();
});
Expand All @@ -147,7 +148,7 @@ module.exports = perspective => {
filter: [["w", "==", yesterday]]
});
let json = await view.to_json();
expect([rdata[3]]).toEqual(json);
expect(json).toEqual([rdata[3]]);
view.delete();
table.delete();
});
Expand All @@ -158,7 +159,7 @@ module.exports = perspective => {
filter: [["w", "!=", yesterday]]
});
let json = await view.to_json();
expect(rdata.slice(0, 3)).toEqual(json);
expect(json).toEqual(rdata.slice(0, 3));
view.delete();
table.delete();
});
Expand All @@ -171,7 +172,7 @@ module.exports = perspective => {
filter: [["y", "in", ["a", "b"]]]
});
let json = await view.to_json();
expect(rdata.slice(0, 2)).toEqual(json);
expect(json).toEqual(rdata.slice(0, 2));
view.delete();
table.delete();
});
Expand All @@ -184,7 +185,7 @@ module.exports = perspective => {
filter: [["y", "not in", ["d"]]]
});
let json = await view.to_json();
expect(rdata.slice(0, 3)).toEqual(json);
expect(json).toEqual(rdata.slice(0, 3));
view.delete();
table.delete();
});
Expand All @@ -210,7 +211,7 @@ module.exports = perspective => {
filter: [["x", ">", 1], ["x", "<", 4]]
});
let json = await view.to_json();
expect(rdata.slice(1, 3)).toEqual(json);
expect(json).toEqual(rdata.slice(1, 3));
view.delete();
table.delete();
});
Expand All @@ -222,7 +223,7 @@ module.exports = perspective => {
filter: [["y", "contains", "a"], ["y", "contains", "b"]]
});
let json = await view.to_json();
expect(rdata.slice(0, 2)).toEqual(json);
expect(json).toEqual(rdata.slice(0, 2));
view.delete();
table.delete();
});
Expand Down Expand Up @@ -261,7 +262,7 @@ module.exports = perspective => {
});
var answer = [{x: 3.5, y: 1}, {x: 4.5, y: 2}];
let result = await view.to_json();
expect(answer).toEqual(result);
expect(result).toEqual(answer);
view.delete();
table.delete();
});
Expand All @@ -275,7 +276,7 @@ module.exports = perspective => {
});
var answer = dataSet;
let result = await view.to_json();
expect(answer).toEqual(result);
expect(result).toEqual(answer);
view.delete();
table.delete();
});
Expand Down
Loading

0 comments on commit 2383987

Please sign in to comment.