Skip to content

Instantly share code, notes, and snippets.

@gpincheiraa
Last active October 8, 2017 00:41
Show Gist options
  • Save gpincheiraa/e8468b2ec429bc2aea59e666561c9de9 to your computer and use it in GitHub Desktop.
Save gpincheiraa/e8468b2ec429bc2aea59e666561c9de9 to your computer and use it in GitHub Desktop.
todoList.component_spec.js- 3 First Impressions using jest for TDD over AngularJS > 1.5.x — Part I
import { TodoListController } from "components/todoList.component"
describe("TodoListController", () => {
let controller
beforeEach(() => {
controller = new TodoListController()
})
it("Should have a defined controller", () => {
expect(controller).toBeInstanceOf(TodoListController)
})
it("Should add a todo item", () => {
const todo = {
name: "Learn Programming using component based approach",
completed: false
}
controller.todosList = []
controller.addTodo(todo)
expect(controller.todosList.length).toBe(1)
expect(controller.todosList[0]).toEqual(todo)
})
it("Should be mark/unmark as completed a certain todo", () => {
const index = 1
controller.todosList = [
{
name: "Learn Programming using component based approach",
completed: false
},
{
name: "Learn Machine Learning",
completed: false
},
{
name: "Finish Medium article",
completed: false
}
]
controller.toggleCheckTodo(index)
expect(controller.todosList[index].completed).toBe(true)
controller.toggleCheckTodo(index)
expect(controller.todosList[index].completed).toBe(false)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment