From 731ffd4a22d7549c609ff86f7ed69f34459741f9 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 12 Aug 2017 09:07:58 +0900 Subject: [PATCH] Add spec for getTodoStatus --- tests/lib/get-todo-status-test.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/lib/get-todo-status-test.js diff --git a/tests/lib/get-todo-status-test.js b/tests/lib/get-todo-status-test.js new file mode 100644 index 00000000..55f951f5 --- /dev/null +++ b/tests/lib/get-todo-status-test.js @@ -0,0 +1,23 @@ +const test = require('ava') +const { getTodoStatus } = require('browser/lib/getTodoStatus') + +// Unit test +test('getTodoStatus should return a correct hash object', t => { + // [input, expected] + const testCases = [ + ['', { total: 0, completed: 0 }], + ['* [ ] a\n', { total: 1, completed: 0 }], + ['* [ ] a\n* [x] a\n', { total: 2, completed: 1 }], + ['- [ ] a\n', { total: 1, completed: 0 }], + ['- [ ] a\n- [x] a\n', { total: 2, completed: 1 }], + ['+ [ ] a\n', { total: 1, completed: 0 }], + ['+ [ ] a\n+ [x] a\n', { total: 2, completed: 1 }] + ] + + testCases.forEach(testCase => { + const [input, expected] = testCase + t.is(getTodoStatus(input).total, expected.total, `Test for getTodoStatus() input: ${input} expected: ${expected.total}`) + t.is(getTodoStatus(input).completed, expected.completed, `Test for getTodoStatus() input: ${input} expected: ${expected.completed}`) + }) +}) +