Skip to content

Instantly share code, notes, and snippets.

@bouzuya
Last active June 11, 2016 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bouzuya/36126cc9e82c6582b90256ce837086a5 to your computer and use it in GitHub Desktop.
Save bouzuya/36126cc9e82c6582b90256ce837086a5 to your computer and use it in GitHub Desktop.
beater の test 定義
// 1. test はいずれかひとつの group に属しないといけないのかが気になる。
import { group } from 'beater';
const g = group('g1');
g.test('t1', () => {
assert(1 === 1);
});
// 2. 1. の callback 版。1. と同じ問題がある。
import { group } from 'beater';
group('g1', test => {
test('t1', () => {
assert(1 === 1);
});
});
// 3. 1. の問題を解決した。
import { group, test } from 'beater';
const g = group('g1');
g.add(test('t1', () => {
assert(1 === 1);
}));
// 4. 3. の callback 版。`group()` と `test()` の意味の違いが気になる。
import { group, test } from 'beater';
group('g1', g => {
g.add(test('t1', () => {
assert(1 === 1);
}));
});
// 5. `group()` と `test()` の意味の違いをなくした。singleton が気になる。長い。 runner が見えるとまずい。
import { runner, group, test } from 'beater';
runner.add(group('g1', g => {
g.add(test('t1', () => {
assert(1 === 1);
}));
}));
// 6. singleton / runner が見える問題を回避。`add()` の副作用感が嫌だ。
import { group, test } from 'beater';
const g = group('g1');
g.add(test('t1', () => {
assert(1 === 1);
}));
export { g as group };
// 7. `add()` の副作用感を回避。`[]` が冗長。
import { group, test } from 'beater';
const g = group('g1', [
test('t1', () => {
assert(1 === 1);
})
]);
export { g as group };
// 8. `[]` を回避。入れ子を避けたい。`export` が気になる。
import { group, test } from 'beater';
const g = group(
'g1',
test('t1', () => {
assert(1 === 1);
})
);
export { g as group };
// 9. 入れ子を避けて `export default`。group への追加を忘れそう。`export default` のトラブル。
import { group, test } from 'beater';
const t1 = test('t1', () => {
assert(1 === 1);
});
const g1 = group('g1', t1);
export default g1;
// 10. 実装が露出しすぎているような……。
import { test } from 'beater';
const t1 = test('t1', () => {
assert(1 === 1);
});
export const tests = [t1];
export const name = 'g1';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment