Skip to content

Commit

Permalink
# Our First Test
Browse files Browse the repository at this point in the history
Writing [self-testing
code](http://www.martinfowler.com/bliki/SelfTestingCode.html) is a
powerful tool for building robust and maintainable software. While there
are many ways of writing test code, I enjoy using [Test Driven
Development](#) for solving problems like this.

Following the ideas of TDD, we'll write the simplest test we can that
results in failure. We expect `deleteNth([], 0)` to return an empty
array. After writing this test and running our test suite, the test
fails:

    deleteNth is not defined

We need to export `deleteNth` from our module under test and import it
into our test file. After making those changes, the test suite is still
failing:

    expected undefined to deeply equal []

Because our `deleteNth` method isn't returning anything our assertion
that it should return `[]` is failing. A quick way to bring our test
suite into a passing state is to have `deleteNth` return `[]`.
  • Loading branch information
pcorey committed Jul 2, 2016
1 parent 7b3878a commit 167e5cf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions index.js
@@ -1,3 +1,3 @@
function deleteNth(arr,x){
// ...
export function deleteNth(arr,x){
return [];
}
7 changes: 5 additions & 2 deletions test/index.js
@@ -1,7 +1,10 @@
import { deleteNth } from "../";
import { expect } from "chai";

describe("index", function() {
describe("deleteNth", function() {

it("works");
it("deletes occurrences of an element if it occurs more than n times", function () {
expect(deleteNth([], 0)).to.deep.equal([]);
});

});

0 comments on commit 167e5cf

Please sign in to comment.