Browse Source

Variations on wrapper.find() assertions.

Frederic G. MARAND 6 years ago
parent
commit
26448dc787
7 changed files with 33 additions and 30 deletions
  1. 1 0
      .eslintrc.js
  2. 11 0
      .idea/runConfigurations/Jest.xml
  3. 0 12
      .idea/runConfigurations/NPM_Test.xml
  4. 2 7
      package.json
  5. 5 0
      src/App.js
  6. 14 10
      src/App.test.js
  7. 0 1
      src/empty-module.js

+ 1 - 0
.eslintrc.js

@@ -16,6 +16,7 @@ module.exports = {
 
     // Test tools: Jest
     "describe": false,
+    "expect": false,
     "it": false,
   },
 

+ 11 - 0
.idea/runConfigurations/Jest.xml

@@ -0,0 +1,11 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="Jest" type="JavaScriptTestRunnerJest" factoryName="Jest">
+    <node-interpreter value="project" />
+    <node-options value="" />
+    <working-dir value="$PROJECT_DIR$" />
+    <jest-options value="--watchAll" />
+    <envs />
+    <scope-kind value="ALL" />
+    <method />
+  </configuration>
+</component>

+ 0 - 12
.idea/runConfigurations/NPM_Test.xml

@@ -1,12 +0,0 @@
-<component name="ProjectRunConfigurationManager">
-  <configuration default="false" name="NPM Test" type="js.build_tools.npm" factoryName="npm">
-    <package-json value="$PROJECT_DIR$/package.json" />
-    <command value="run" />
-    <scripts>
-      <script value="test" />
-    </scripts>
-    <node-interpreter value="project" />
-    <envs />
-    <method />
-  </configuration>
-</component>

+ 2 - 7
package.json

@@ -9,12 +9,6 @@
     "enzyme-adapter-react-16": "^1.1.1",
     "react-scripts": "1.1.1"
   },
-  "jest": {
-    "moduleNameMapper": {
-      "\\.(css|jpg|png|svg)$": "<rootDir>/empty-module.js"
-    },
-    "rootDir": "src"
-  },
   "license": "proprietary",
   "name": "egghead_enzyme",
   "private": true,
@@ -23,7 +17,8 @@
     "build": "react-scripts build",
     "eject": "react-scripts eject",
     "start": "react-scripts start",
-    "test": "jest",
+    "test": "react-scripts test",
+    "test_jest": "jest",
     "test_from_create_react": "react-scripts test --env=jsdom"
   }
 }

+ 5 - 0
src/App.js

@@ -15,6 +15,11 @@ class App extends Component {
         <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>
         <Test/>
       </div>
     );

+ 14 - 10
src/App.test.js

@@ -4,19 +4,23 @@ import App from "./App";
 import { configure, shallow } from "enzyme";
 import Adapter from "enzyme-adapter-react-16";
 
-// Configure Enzyme for the React version we're using.
+// Configure Enzyme for the React version we are using.
 // Could be in a test setup file. Required for React 16, 15, 0.14, 0.13.
 configure({ adapter: new Adapter() });
 
 describe("<App />>", () => {
-  it("should render App", () => {
-    const wrapper = shallow(<App />, {
-      // Pass a context to component.
-      context: {},
-      // Disable component mount lifecycle methods, as well as update after
-      // setProps() and setContext().
-      disableLifecycleMethods: true,
-    });
-    console.log(wrapper.debug());
+  const wrapper = shallow(<App />);
+
+  it("should contain 1 p element", () => {
+    // There is one <p> in <App />: only one shoud be present in shallow rendering.
+    expect(wrapper.find("p").length).toBe(1);
+
+    expect(wrapper.find("p.App-intro").exists()).toBe(true);
+
+    expect(wrapper.find("ul").hasClass("tyler")).toBe(true);
+
+    expect(wrapper.find("ul").children().length).toBe(3);
+
+    expect(wrapper.find("h1").text()).toBe("Welcome to React");
   });
 });

+ 0 - 1
src/empty-module.js

@@ -1 +0,0 @@
-module.exports = "";