Skip to content

Commit

Permalink
chore: make them pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed May 29, 2018
1 parent 003e621 commit 7e3061e
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 169 deletions.
2 changes: 1 addition & 1 deletion __tests__/async-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import la from '../src';
import la from '../src'

describe('lazy-ass.async', () => {
it('it is a function', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/default-export-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import la from '../src';
import la from '../src'

describe('lazy-ass as default export', () => {
it('does not throw if condition is true', () => {
Expand Down
64 changes: 32 additions & 32 deletions __tests__/function-test.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
import { lazyAss } from '../src';
import { lazyAss } from '../src'

describe('function as condition', function() {
it('evaluates the function', function() {
var called;
var called
function condition() {
called = true;
return true;
called = true
return true
}

lazyAss(condition);
lazyAss(condition)
expect(called).toBe(true)
});
})

it('no result is failure', function() {
function noreturn() {}

expect(function() {
lazyAss(noreturn);
lazyAss(noreturn)
}).toThrowError()
});
})

it('adds condition function source to message', function() {
function myCondition() {}
expect(function() {
lazyAss(myCondition);
}).toThrowError(/myCondition/);
});
lazyAss(myCondition)
}).toThrowError(/myCondition/)
})

it('allows anonymous functions', function() {
var called;
var called
lazyAss(function() {
return true;
});
return true
})
lazyAss(function() {
return true;
}, 'everything is ok');
return true
}, 'everything is ok')
lazyAss(function() {
called = true;
return true;
}, 'everything is ok');
expect(called).toBe(true);
called = true
return true
}, 'everything is ok')
expect(called).toBe(true)

expect(function() {
lazyAss(function() {});
}).toThrowError();
});
lazyAss(function() {})
}).toThrowError()
})

it('has access via closure', function() {
var foo = 2,
bar = 3;
bar = 3
expect(function() {
lazyAss(function() {
return foo + bar === 6;
}, 'addition');
return foo + bar === 6
}, 'addition')
}).toThrowErrorMatchingSnapshot()
});
})

it('example', function() {
var foo = 2,
bar = 2;
bar = 2
function isValidPair() {
return foo + bar === 4;
return foo + bar === 4
}
lazyAss(isValidPair, 'foo', foo, 'bar', bar);
});
});
lazyAss(isValidPair, 'foo', foo, 'bar', bar)
})
})
116 changes: 58 additions & 58 deletions __tests__/lazy-ass-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lazyAss as la } from '../src';
import { lazyAss as la } from '../src'

describe('lazy-ass', () => {
it('does not throw if condition is true', () => {
Expand All @@ -17,115 +17,115 @@ describe('lazy-ass', () => {

it('does not evaluate function if condition is true', () => {
function foo() {
throw new Error('Foo has been called');
throw new Error('Foo has been called')
}
la(true, foo)
})

it('calls functions to form message', function () {
var called = 0;
it('calls functions to form message', function() {
var called = 0
function foo() {
called += 1;
return 'foo';
called += 1
return 'foo'
}
expect(function () {
la(false, foo, 'bar', foo);
expect(function() {
la(false, foo, 'bar', foo)
}).toThrowErrorMatchingSnapshot()
// foo was called twice
expect(called).toBe(2)
});
})

it('handles exception if thrown from function', function () {
var called = 0;
it('handles exception if thrown from function', function() {
var called = 0
function foo() {
called += 1;
throw new Error('Oh no!');
called += 1
throw new Error('Oh no!')
}
expect(function () {
la(false, foo, 'bar', foo);
expect(function() {
la(false, foo, 'bar', foo)
}).toThrowErrorMatchingSnapshot()
expect(called).toBe(2)
});
})

it('JSON stringifies arrays', function () {
expect(function () {
la(false, [1, 2, 3]);
it('JSON stringifies arrays', function() {
expect(function() {
la(false, [1, 2, 3])
}).toThrowErrorMatchingSnapshot()
});
})

it('JSON stringifies objects', function () {
var obj = { foo: 'foo' };
expect(function () {
la(false, obj);
it('JSON stringifies objects', function() {
var obj = { foo: 'foo' }
expect(function() {
la(false, obj)
}).toThrowErrorMatchingSnapshot()
});
})

it('JSON.stringify skip undefined property', function () {
it('JSON.stringify skip undefined property', function() {
var obj = {
foo: 'foo',
bad: undefined
};
var str = JSON.stringify(obj);
}
var str = JSON.stringify(obj)
expect(str).toMatchSnapshot()
});
})

it('JSON.stringify with custom replacer', function () {
it('JSON.stringify with custom replacer', function() {
var obj = {
foo: 'foo',
bad: undefined
};
}
function replacer(key, value) {
if (value === undefined) {
return 'null';
return 'null'
}
return value;
return value
}
var str = JSON.stringify(obj, replacer);
var str = JSON.stringify(obj, replacer)
expect(str).toMatchSnapshot()
});
})

it('nested JSON.stringify with custom replacer', function () {
it('nested JSON.stringify with custom replacer', function() {
var obj = {
foo: 'foo',
bar: {
baz: 'value'
}
};
}
function replacer(key, value) {
if (value === undefined) {
return null;
return null
}
return value;
return value
}
var str = JSON.stringify(obj, replacer);
var str = JSON.stringify(obj, replacer)
expect(str).toMatchSnapshot()
});
})

it('JSON stringifies undefined value of a property', function () {
it('JSON stringifies undefined value of a property', function() {
var obj = {
foo: 'foo',
bad: undefined
};
expect(function () {
la(false, obj);
}
expect(function() {
la(false, obj)
}).toThrowErrorMatchingSnapshot()
});
})

it('takes error name and message', function () {
expect(function () {
la(false, new Error('hi there'));
it('takes error name and message', function() {
expect(function() {
la(false, new Error('hi there'))
}).toThrowErrorMatchingSnapshot()
});
})

it('does adds spaces between arguments', function () {
expect(function () {
la(false, 'foo', 'bar', 42);
it('does adds spaces between arguments', function() {
expect(function() {
la(false, 'foo', 'bar', 42)
}).toThrowErrorMatchingSnapshot()
});
})

it('does not add space if previous one has newline', function () {
expect(function () {
la(false, 'foo\n', 'bar', 42);
it('does not add space if previous one has newline', function() {
expect(function() {
la(false, 'foo\n', 'bar', 42)
}).toThrowErrorMatchingSnapshot()
});
})
})
66 changes: 33 additions & 33 deletions __tests__/serialize-test.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
import { lazyAss } from '../src';
import { lazyAss } from '../src'

describe('serializes circular objects', function() {
var foo:any = {
bar: 'bar',
};
foo.foo = foo;
var foo: any = {
bar: 'bar'
}
foo.foo = foo

it('can handle one circular object', function() {
var msg = 'foo has circular reference';
var msg = 'foo has circular reference'
expect(function() {
lazyAss(false, msg, foo);
lazyAss(false, msg, foo)
}).toThrowErrorMatchingSnapshot()
});
});
})
})

describe('serialize arguments', function() {
const foo:any = function foo() {
lazyAss(false, arguments);
const foo: any = function foo() {
lazyAss(false, arguments)
}
it('serializes arguments object', function() {
expect(function() {
foo('something');
foo('something')
}).toThrowErrorMatchingSnapshot()
});
});
})
})

describe('gives context to non-serializable objects', function() {
it('prints keys in non-serializable objects', function() {
var foo: any = {
bar: 'bar',
};
foo.foo = foo;
bar: 'bar'
}
foo.foo = foo
expect(function() {
lazyAss(false, foo);
lazyAss(false, foo)
}).toThrowErrorMatchingSnapshot()
});
})

it('handles several objects', function() {
var foo: any = {
bar: 'bar',
};
foo.foo = foo;
bar: 'bar'
}
foo.foo = foo

var bar = {
foo: foo,
};
foo: foo
}

expect(function() {
lazyAss(false, foo, bar);
lazyAss(false, foo, bar)
}).toThrowErrorMatchingSnapshot()
});
})

it('can handle array with circular objects', function() {
var foo:any = {
bar: 'bar',
};
foo.foo = foo;
var foo: any = {
bar: 'bar'
}
foo.foo = foo

expect(function() {
lazyAss(false, 'problem with foo', [foo]);
lazyAss(false, 'problem with foo', [foo])
}).toThrowErrorMatchingSnapshot()
});
});
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"test": "npm run unit && npm run jest",
"unit": "mocha test/commonjs.spec.js",
"jest": "jest",
"pretty": "prettier --single-quote --write src/*.ts __tests__/*.ts"
"pretty": "prettier --single-quote --no-semi --write src/*.ts __tests__/*.ts"
},
"jest": {
"transform": {
Expand Down
Loading

0 comments on commit 7e3061e

Please sign in to comment.