Skip to content

Commit 486a8ea

Browse files
committed
Fix tests
1 parent df6ceef commit 486a8ea

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

test/react/rails/view_helper_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ class ViewHelperTest < ActionDispatch::IntegrationTest
129129
test 'react server rendering also gets mounted on client' do
130130
visit '/server/1'
131131
assert_match(/data-react-class=\"TodoList\"/, page.html)
132-
assert_match(/data-react-checksum/, page.html)
133132
assert_match(/yep/, page.find("#status").text)
134133
end
135134

test/react/server_rendering/sprockets_renderer_test.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,34 @@ class SprocketsRendererTest < ActiveSupport::TestCase
2424

2525
test '#render replays console messages' do
2626
result = @renderer.render("TodoListWithConsoleLog", {todos: ["log some messages"]})
27-
assert_match('console.log.apply(console, ["got initial state"])', result)
28-
assert_match('console.warn.apply(console, ["mounted component"])', result)
29-
assert_match('console.error.apply(console, ["rendered!","foo"])', result)
27+
assert_match(/console.log.apply\(console, \["got initial state"\]\)/, result)
28+
assert_match(/console.warn.apply\(console, \["mounted component"\]\)/, result)
29+
assert_match(/console.error.apply\(console, \["rendered!","foo"\]\)/, result)
3030
end
3131

3232
test '#render console messages can be disabled' do
3333
no_log_renderer = React::ServerRendering::SprocketsRenderer.new({replay_console: false})
3434
result = no_log_renderer.render("TodoListWithConsoleLog", {todos: ["log some messages"]})
35-
assert_no_match('console.log.apply(console, ["got initial state"])', result)
36-
assert_no_match('console.warn.apply(console, ["mounted component"])', result)
37-
assert_no_match('console.error.apply(console, ["rendered!","foo"])', result)
35+
assert_no_match(/console.log.apply\(console, \["got initial state"\]\)/, result)
36+
assert_no_match(/console.warn.apply\(console, \["mounted component"\]\)/, result)
37+
assert_no_match(/console.error.apply\(console, \["rendered!","foo"\]\)/, result)
3838
end
3939

4040
test '#render errors include stack traces' do
4141
err = assert_raises React::ServerRendering::SprocketsRenderer::PrerenderError do
4242
@renderer.render("NonExistentComponent", {})
4343
end
44-
assert_match("ReferenceError", err.to_s)
45-
assert_match("NonExistentComponent", err.to_s, "it names the component")
44+
assert_match(/ReferenceError/, err.to_s)
45+
assert_match(/NonExistentComponent/, err.to_s, "it names the component")
4646
assert_match(/\n/, err.to_s, "it includes the multi-line backtrace")
4747
end
4848

4949
test '.new accepts any filenames' do
5050
limited_renderer = React::ServerRendering::SprocketsRenderer.new(files: ["react.js", "components/Todo.js"])
51-
assert_match("get a real job</li>", limited_renderer.render("Todo", {todo: "get a real job"}))
51+
assert_match(/get a real job<\/li>/, limited_renderer.render("Todo", {todo: "get a real job"}))
5252
err = assert_raises React::ServerRendering::SprocketsRenderer::PrerenderError do
5353
limited_renderer.render("TodoList", {todos: []})
5454
end
55-
assert_match("ReferenceError", err.to_s, "it doesnt load other files")
55+
assert_match(/ReferenceError/, err.to_s, "it doesnt load other files")
5656
end
5757
end

test/react/server_rendering_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ReactServerRenderingTest < ActiveSupport::TestCase
2626
end
2727

2828
test '.create_renderer makes a renderer with initialization options' do
29-
mock_renderer = MiniTest::Mock.new
29+
mock_renderer = Minitest::Mock.new
3030
mock_renderer.expect(:new, :fake_renderer, [{mock: true}])
3131
React::ServerRendering.renderer = mock_renderer
3232
React::ServerRendering.renderer_options = {mock: true}

test/react_test.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@
22
require 'fileutils'
33

44
class ReactTest < ActionDispatch::IntegrationTest
5+
setup do
6+
Rails.application.assets.send(:expire_index!)
7+
FileUtils.rm_r(CACHE_PATH) if CACHE_PATH.exist?
8+
end
9+
510
test 'asset pipeline should deliver drop-in react file replacement' do
611
app_react_file_path = File.expand_path("../dummy/vendor/assets/javascripts/react.js", __FILE__)
712

813
react_file_token = "'test_confirmation_token_react_content_non_production';\n";
914
File.write(app_react_file_path, react_file_token)
1015

16+
asset_pipeline_length = Rails.application.assets.find_asset('react').to_s.length
1117
get '/assets/react.js'
1218

1319
File.unlink(app_react_file_path)
1420
FileUtils.rm_r CACHE_PATH if CACHE_PATH.exist?
1521

1622
assert_response :success
17-
assert_equal react_file_token, @response.body
23+
assert_equal react_file_token.length, asset_pipeline_length, "The asset pipeline serves the drop-in file"
24+
assert_equal react_file_token.length, @response.body.length, "The asset route serves the drop-in file"
1825
end
1926

2027
test 'precompiling assets works' do

test/server_rendered_html_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def wait_to_ensure_asset_pipeline_detects_changes
4646

4747
# Make sure they're not when we don't ask for them
4848
get '/server/console_example_suppressed'
49-
assert_match('Console Logged', response.body)
49+
assert_match(/Console Logged/, response.body)
5050
assert_no_match(/console.log/, response.body)
5151
assert_no_match(/console.warn/, response.body)
5252
assert_no_match(/console.error/, response.body)

test/test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require "rails/test_help"
66
require "rails/generators"
77
require "pathname"
8+
require 'minitest/mock'
89

910
CACHE_PATH = Pathname.new File.expand_path("../dummy/tmp/cache", __FILE__)
1011

0 commit comments

Comments
 (0)