Skip to content

Use prettier for tests #1403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions __tests__/ArraySeq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import { Seq } from '../';

describe('ArraySequence', () => {

it('every is true when predicate is true for all entries', () => {
expect(Seq([]).every(() => false)).toBe(true);
expect(Seq([1, 2, 3]).every(v => v > 0)).toBe(true);
Expand Down Expand Up @@ -42,7 +41,14 @@ describe('ArraySequence', () => {
function studly(letter, index) {
return index % 2 === 0 ? letter : letter.toUpperCase();
}
const result = i.reverse().take(10).reverse().take(5).map(studly).toArray().join('');
const result = i
.reverse()
.take(10)
.reverse()
.take(5)
.map(studly)
.toArray()
.join('');
expect(result).toBe('qRsTu');
});

Expand All @@ -67,8 +73,19 @@ describe('ArraySequence', () => {
expect(seq.take(5).toArray().length).toBe(5);
expect(seq.filter(x => x % 2 === 1).toArray().length).toBe(2);
expect(seq.toKeyedSeq().flip().size).toBe(10);
expect(seq.toKeyedSeq().flip().flip().size).toBe(10);
expect(seq.toKeyedSeq().flip().flip().toArray().length).toBe(10);
expect(
seq
.toKeyedSeq()
.flip()
.flip().size
).toBe(10);
expect(
seq
.toKeyedSeq()
.flip()
.flip()
.toArray().length
).toBe(10);
});

it('can be iterated', () => {
Expand Down
109 changes: 57 additions & 52 deletions __tests__/Conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

///<reference path='../resources/jest.d.ts'/>

import * as jasmineCheck from "jasmine-check";
import {fromJS, is, List, Map, OrderedMap, Record} from "../";
import * as jasmineCheck from 'jasmine-check';
import { fromJS, is, List, Map, OrderedMap, Record } from '../';
jasmineCheck.install();

// Symbols
Expand All @@ -19,72 +19,73 @@ describe('Conversion', () => {
const js = {
deepList: [
{
position: "first",
position: 'first'
},
{
position: "second",
position: 'second'
},
{
position: "third",
},
position: 'third'
}
],
deepMap: {
a: "A",
b: "B",
a: 'A',
b: 'B'
},
emptyMap: Object.create(null),
point: {x: 10, y: 20},
string: "Hello",
list: [1, 2, 3],
point: { x: 10, y: 20 },
string: 'Hello',
list: [1, 2, 3]
};

const Point = Record({x: 0, y: 0}, 'Point');
const Point = Record({ x: 0, y: 0 }, 'Point');

const immutableData = Map({
deepList: List.of(
Map({
position: "first",
position: 'first'
}),
Map({
position: "second",
position: 'second'
}),
Map({
position: "third",
}),
position: 'third'
})
),
deepMap: Map({
a: "A",
b: "B",
a: 'A',
b: 'B'
}),
emptyMap: Map(),
point: Map({x: 10, y: 20}),
string: "Hello",
list: List.of(1, 2, 3),
point: Map({ x: 10, y: 20 }),
string: 'Hello',
list: List.of(1, 2, 3)
});

const immutableOrderedData = OrderedMap({
deepList: List.of(
OrderedMap({
position: "first",
position: 'first'
}),
OrderedMap({
position: "second",
position: 'second'
}),
OrderedMap({
position: "third",
}),
position: 'third'
})
),
deepMap: OrderedMap({
a: "A",
b: "B",
a: 'A',
b: 'B'
}),
emptyMap: OrderedMap(),
point: new Point({x: 10, y: 20}),
string: "Hello",
list: List.of(1, 2, 3),
point: new Point({ x: 10, y: 20 }),
string: 'Hello',
list: List.of(1, 2, 3)
});

const immutableOrderedDataString = 'OrderedMap { ' +
const immutableOrderedDataString =
'OrderedMap { ' +
'"deepList": List [ ' +
'OrderedMap { ' +
'"position": "first"' +
Expand All @@ -106,18 +107,20 @@ describe('Conversion', () => {
'"list": List [ 1, 2, 3 ]' +
' }';

const nonStringKeyMap = OrderedMap().set(1, true).set(false, "foo");
const nonStringKeyMap = OrderedMap()
.set(1, true)
.set(false, 'foo');
const nonStringKeyMapString = 'OrderedMap { 1: true, false: "foo" }';

it('Converts deep JS to deep immutable sequences', () => {
expect(fromJS(js)).toEqual(immutableData);
});

it('Throws when provided circular reference', () => {
const o = {a: {b: {c: null as any}}};
const o = { a: { b: { c: null as any } } };
o.a.b.c = o;
expect(() => fromJS(o)).toThrow(
'Cannot convert circular structure to Immutable',
'Cannot convert circular structure to Immutable'
);
});

Expand All @@ -126,7 +129,9 @@ describe('Conversion', () => {
if (key === 'point') {
return new Point(sequence);
}
return Array.isArray(this[key]) ? sequence.toList() : sequence.toOrderedMap();
return Array.isArray(this[key])
? sequence.toList()
: sequence.toOrderedMap();
});
expect(seq).toEqual(immutableOrderedData);
expect(seq.toString()).toEqual(immutableOrderedDataString);
Expand All @@ -137,7 +142,9 @@ describe('Conversion', () => {
const seq1 = fromJS(js, function(key, sequence, keypath) {
expect(arguments.length).toBe(3);
paths.push(keypath);
return Array.isArray(this[key]) ? sequence.toList() : sequence.toOrderedMap();
return Array.isArray(this[key])
? sequence.toList()
: sequence.toOrderedMap();
});
expect(paths).toEqual([
[],
Expand All @@ -148,12 +155,11 @@ describe('Conversion', () => {
['deepMap'],
['emptyMap'],
['point'],
['list'],
['list']
]);
const seq2 = fromJS(js, function(key, sequence) {
expect(arguments[2]).toBe(undefined);
});

});

it('Prints keys as JS values', () => {
Expand Down Expand Up @@ -181,36 +187,35 @@ describe('Conversion', () => {
Model.prototype.toJSON = function() {
return 'model';
};
expect(
Map({a: new Model()}).toJS(),
).toEqual({a: {}});
expect(
JSON.stringify(Map({a: new Model()})),
).toEqual('{"a":"model"}');
expect(Map({ a: new Model() }).toJS()).toEqual({ a: {} });
expect(JSON.stringify(Map({ a: new Model() }))).toEqual('{"a":"model"}');
});

it('is conservative with array-likes, only accepting true Arrays.', () => {
expect(fromJS({1: 2, length: 3})).toEqual(
Map().set('1', 2).set('length', 3),
expect(fromJS({ 1: 2, length: 3 })).toEqual(
Map()
.set('1', 2)
.set('length', 3)
);
expect(fromJS('string')).toEqual('string');
});

check.it('toJS isomorphic value', {maxSize: 30}, [gen.JSONValue], v => {
check.it('toJS isomorphic value', { maxSize: 30 }, [gen.JSONValue], v => {
const imm = fromJS(v);
expect(imm && imm.toJS ? imm.toJS() : imm).toEqual(v);
});

it('Explicitly convert values to string using String constructor', () => {
expect(() => fromJS({foo: Symbol('bar')}) + '').not.toThrow();
expect(() => fromJS({ foo: Symbol('bar') }) + '').not.toThrow();
expect(() => Map().set('foo', Symbol('bar')) + '').not.toThrow();
expect(() => Map().set(Symbol('bar'), 'foo') + '').not.toThrow();
});

it('Converts an immutable value of an entry correctly', () => {
const arr = [{key: "a"}];
const result = fromJS(arr).entrySeq().toJS();
expect(result).toEqual([[0, {key: "a"}]]);
const arr = [{ key: 'a' }];
const result = fromJS(arr)
.entrySeq()
.toJS();
expect(result).toEqual([[0, { key: 'a' }]]);
});

});
42 changes: 20 additions & 22 deletions __tests__/Equality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jasmineCheck.install();
import { is, List, Map, Seq, Set } from '../';

describe('Equality', () => {

function expectIs(left, right) {
const comparison = is(left, right);
expect(comparison).toBe(true);
Expand Down Expand Up @@ -47,29 +46,30 @@ describe('Equality', () => {
expectIs(0, -0);
expectIs(NaN, 0 / 0);

const str = "hello";
const str = 'hello';
expectIs(str, str);
expectIs(str, "hello");
expectIsNot("hello", "HELLO");
expectIsNot("hello", "goodbye");
expectIs(str, 'hello');
expectIsNot('hello', 'HELLO');
expectIsNot('hello', 'goodbye');

const array = [1, 2, 3];
expectIs(array, array);
expectIsNot(array, [1, 2, 3]);

const object = {key: 'value'};
const object = { key: 'value' };
expectIs(object, object);
expectIsNot(object, {key: 'value'});
expectIsNot(object, { key: 'value' });
});

it('dereferences things', () => {
const ptrA = {foo: 1}, ptrB = {foo: 2};
const ptrA = { foo: 1 },
ptrB = { foo: 2 };
expectIsNot(ptrA, ptrB);
ptrA.valueOf = ptrB.valueOf = function() {
return 5;
};
expectIs(ptrA, ptrB);
const object = {key: 'value'};
const object = { key: 'value' };
ptrA.valueOf = ptrB.valueOf = function() {
return object;
};
Expand Down Expand Up @@ -125,29 +125,27 @@ describe('Equality', () => {
const genVal = gen.oneOf([
gen.map(List, gen.array(genSimpleVal, 0, 4)),
gen.map(Set, gen.array(genSimpleVal, 0, 4)),
gen.map(Map, gen.array(gen.array(genSimpleVal, 2), 0, 4)),
gen.map(Map, gen.array(gen.array(genSimpleVal, 2), 0, 4))
]);

check.it('has symmetric equality', {times: 1000}, [genVal, genVal], (a, b) => {
expect(is(a, b)).toBe(is(b, a));
});
check.it(
'has symmetric equality',
{ times: 1000 },
[genVal, genVal],
(a, b) => {
expect(is(a, b)).toBe(is(b, a));
}
);

check.it('has hash equality', {times: 1000}, [genVal, genVal], (a, b) => {
check.it('has hash equality', { times: 1000 }, [genVal, genVal], (a, b) => {
if (is(a, b)) {
expect(a.hashCode()).toBe(b.hashCode());
}
});

describe('hash', () => {

it('differentiates decimals', () => {
expect(
Seq([1.5]).hashCode(),
).not.toBe(
Seq([1.6]).hashCode(),
);
expect(Seq([1.5]).hashCode()).not.toBe(Seq([1.6]).hashCode());
});

});

});
3 changes: 1 addition & 2 deletions __tests__/IndexedSeq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jasmineCheck.install();
import { Seq } from '../';

describe('IndexedSequence', () => {

it('maintains skipped offset', () => {
const seq = Seq(['A', 'B', 'C', 'D', 'E']);

Expand All @@ -23,7 +22,7 @@ describe('IndexedSequence', () => {
[0, 'B'],
[1, 'C'],
[2, 'D'],
[3, 'E'],
[3, 'E']
]);

expect(operated.first()).toEqual('B');
Expand Down
Loading