HyperSpec
Adding client side testing to RSpec
it "will update the TodoIndex", js: true do
# mounts the TodoIndex component (client side)
mount 'TodoIndex'
# Todo is an ActiveRecord Model
# create a new Todo on the server (we could use FactoryBot of course)
todo_1 = Todo.create(title: 'this todo created on the server')
# verify that UI got updated
expect(find('.ToDoItem-Text').text).to eq todo_1.title
# verify that the count of Todos on the client side DB matches the server
expect { Todo.count }.on_client_to eq Todo.count
# now create another Todo on the client
new_todo_title = 'this todo created on the client'
# note that local variables are copied from the server to the client
on_client { Todo.create(title: new_todo_title) }
# the Todo should now be reflected on the server
expect(Todo.last.title).to eq new_todo_title
endLast updated
Was this helpful?