Sha256: c6b4ce5f40e4ef8c7323e96f18abc606c1569e03b6e06a8c0ea7c8ffef413e89
Contents?: true
Size: 1.54 KB
Versions: 1
Compression:
Stored size: 1.54 KB
Contents
require_relative "../lib/redux" require "minitest/autorun" describe Redux do describe Redux::Store do it "has nil as initial state if none given" do store = Redux::Store.new assert_equal nil, store.state end describe "example: counter reducer" do reducer = ->(state = 0, action){ case action['type'] when 'INCREMENT' state + 1 when 'DECREMENT' state - 1 else state end } it "uses passed initial state" do store = Redux::Store.new(0, &reducer) assert_equal 0, store.state end it "can be incremented" do store = Redux::Store.new(0, &reducer) store.dispatch "type" => "INCREMENT" assert_equal 1, store.state end it "can be decremented" do store = Redux::Store.new(0, &reducer) store.dispatch "type" => "DECREMENT" assert_equal -1, store.state end it "can be subscribed to state changes" do callback_called = false store = Redux::Store.new(0, &reducer) store.subscribe { callback_called = true } store.dispatch "type" => "DECREMENT" assert_equal true, callback_called end it "can be unsubscribed from state changes" do callback_called = false store = Redux::Store.new(0, &reducer) unsubscribe = store.subscribe { callback_called = true } unsubscribe.call store.dispatch "type" => "DECREMENT" assert_equal false, callback_called end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
redux-0.1.0 | spec/redux_spec.rb |