Browse Source

video9: fully render components with mount()/unmount().

Frederic G. MARAND 8 năm trước cách đây
mục cha
commit
10e75021bd
2 tập tin đã thay đổi với 76 bổ sung2 xóa
  1. 23 1
      src/App.test.js
  2. 53 1
      src/__snapshots__/App.test.js.snap

+ 23 - 1
src/App.test.js

@@ -9,7 +9,7 @@ import toJson from "enzyme-to-json";
 // Could be in a test setup file. Required for React 16, 15, 0.14, 0.13.
 configure({ adapter: new Adapter() });
 
-describe("<App />>", () => {
+describe("<App /> shallow rendering", () => {
   const wrapper = shallow(<App />);
 
   it("should find its elements", () => {
@@ -48,6 +48,28 @@ describe("<App />>", () => {
   });
 });
 
+describe("<App /> mount rendering", () => {
+  it("h1 contains correct text", () => {
+    // Second parameter is optional.
+    const wrapper = mount(<App />, {
+      context: {},
+      attachTo: document.createElement("div"),
+    });
+
+    expect(wrapper.find("h1").text()).toBe("Welcome to React");
+    // Tests can affect each other if mounted components are not unmounted,
+    // since they will remain mounted in the same DOM.
+    // Unmount() can also be used to simulate an unmount/mount cycle in React.
+    wrapper.unmount();
+  });
+
+  it("matches the snapshot", () => {
+    const tree = mount(<App />);
+    expect(toJson(tree)).toMatchSnapshot();
+    tree.unmount();
+  });
+});
+
 describe("<Link>", () => {
   const expected = "www.google.com";
 

+ 53 - 1
src/__snapshots__/App.test.js.snap

@@ -1,6 +1,58 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
-exports[`<App />> matches the snapshot 1`] = `
+exports[`<App /> mount rendering matches the snapshot 1`] = `
+<MasterControlProgram>
+  <div
+    className="App"
+  >
+    <header
+      className="App-header"
+    >
+      <img
+        alt="logo"
+        className="App-logo"
+        src="logo.svg"
+      />
+      <h1
+        className="App-title"
+      >
+        Welcome to React
+      </h1>
+    </header>
+    <heading
+      text="Some title"
+    >
+      <div>
+        Some title
+      </div>
+    </heading>
+    <p
+      className="App-intro"
+    >
+      To get started, edit 
+      <code>
+        src/App.js
+      </code>
+       and save to reload.
+    </p>
+    <ul
+      className="tyler"
+    >
+      <li>
+        First
+      </li>
+      <li>
+        Second
+      </li>
+      <li>
+        Third
+      </li>
+    </ul>
+  </div>
+</MasterControlProgram>
+`;
+
+exports[`<App /> shallow rendering matches the snapshot 1`] = `
 <div
   className="App"
 >

PANIC: session(release): write data/sessions/f/9/f92a8791e9201a66: no space left on device

PANIC

session(release): write data/sessions/f/9/f92a8791e9201a66: no space left on device
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/session@v1.0.3/session.go:204 (0xb13e07)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/context.go:80 (0x967b75)
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/inject@v0.0.0-20200308113650-138e5925c53b/inject.go:157 (0x9512ee)
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/inject@v0.0.0-20200308113650-138e5925c53b/inject.go:135 (0x951205)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/context.go:124 (0x967cc4)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/context.go:114 (0x967bf6)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/recovery.go:161 (0x15baec4)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/logger.go:40 (0x96b257)
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/inject@v0.0.0-20200308113650-138e5925c53b/inject.go:157 (0x9512ee)
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/inject@v0.0.0-20200308113650-138e5925c53b/inject.go:135 (0x951205)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/context.go:124 (0x967cc4)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/router.go:187 (0x972959)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/router.go:304 (0x973a01)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/macaron.go:218 (0x96c572)
/my/cache/.heroku/go/go1.26.3/go/src/net/http/server.go:3311 (0x85a5cd)
/my/cache/.heroku/go/go1.26.3/go/src/net/http/server.go:2073 (0x837f6f)
/my/cache/.heroku/go/go1.26.3/go/src/runtime/asm_amd64.s:1771 (0x493380)