浏览代码

feat: component testing

RyaneMax 8 月之前
父节点
当前提交
443cccc2db

+ 11 - 6
cypress.config.ts

@@ -1,10 +1,15 @@
-import { defineConfig } from 'cypress'
+import { defineConfig } from "cypress";
 
 export default defineConfig({
-  
   e2e: {
-    'baseUrl': 'http://localhost:4200'
+    baseUrl: "http://localhost:4200",
   },
-  
-  
-})
+
+  component: {
+    devServer: {
+      framework: "angular",
+      bundler: "webpack",
+    },
+    specPattern: "**/*.cy.ts",
+  },
+});

+ 12 - 0
cypress/support/component-index.html

@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width,initial-scale=1.0">
+    <title>Components App</title>
+  </head>
+  <body>
+    <div data-cy-root></div>
+  </body>
+</html>

+ 39 - 0
cypress/support/component.ts

@@ -0,0 +1,39 @@
+// ***********************************************************
+// This example support/component.ts is processed and
+// loaded automatically before your test files.
+//
+// This is a great place to put global configuration and
+// behavior that modifies Cypress.
+//
+// You can change the location of this file or turn off
+// automatically serving support files with the
+// 'supportFile' configuration option.
+//
+// You can read more here:
+// https://on.cypress.io/configuration
+// ***********************************************************
+
+// Import commands.js using ES2015 syntax:
+import './commands'
+
+// Alternatively you can use CommonJS syntax:
+// require('./commands')
+
+import { mount } from 'cypress/angular'
+
+// Augment the Cypress namespace to include type definitions for
+// your custom command.
+// Alternatively, can be defined in cypress/support/component.d.ts
+// with a <reference path="./component" /> at the top of your spec.
+declare global {
+  namespace Cypress {
+    interface Chainable {
+      mount: typeof mount
+    }
+  }
+}
+
+Cypress.Commands.add('mount', mount)
+
+// Example use:
+// cy.mount(MyComponent)

+ 14 - 0
src/modules/study/case-angular/comps/edit-ratio-star/__test__/EditRatioStartComponent.cy.ts

@@ -0,0 +1,14 @@
+// counter.cy.ts
+import { mount } from 'cypress/angular';
+import { EditRatioStarComponent } from '../edit-ratio-star.component';
+
+
+describe('Edit-Ratio-Star', () => {
+    it('should render the initial count', () => {
+      mount(EditRatioStarComponent);
+      cy.get('.list ion-icon').eq(0).click({force:true});
+      
+    });
+  
+  
+  });