开玩笑的模拟功能,忽略传入的值

时间:2019-12-12 23:49:06

标签: javascript reactjs jestjs enzyme

我有一个超级简单的测试,只是拒绝查看我传递的值:

正在测试的组件:{ "name": "sosapazfront-end", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "@agm/core": "^1.0.0-beta.6", "@angular/animations": "~7.2.0", "@angular/common": "~7.2.0", "@angular/compiler": "~7.2.0", "@angular/core": "~7.2.0", "@angular/forms": "~7.2.0", "@angular/platform-browser": "~7.2.0", "@angular/platform-browser-dynamic": "~7.2.0", "@angular/router": "~7.2.0", "@ng-bootstrap/ng-bootstrap": "^4.1.3", "@types/jspdf": "^1.3.1", "angular-tree-component": "^8.4.1", "angular2-text-mask": "^9.0.0", "babel-loader": "^8.0.5", "bootstrap": "^4.3.1", "core-js": "^2.5.4", "jquery": "^3.4.1", "jspdf": "^1.5.3", "jspdf-autotable": "^3.2.4", "lodash": "^4.17.15", "ng2-currency-mask": "^5.3.1", "ng2-order-pipe": "^0.1.5", "ng2-search-filter": "^0.5.1", "ngx-mask": "^7.9.10", "ngx-pagination": "^3.2.1", "ngx-perfect-scrollbar": "^7.2.1", "ngx-print": "^1.2.0-beta.3", "ngx-select-dropdown": "^1.0.1", "ngx-socket-io": "^2.1.1", "popper": "^1.0.1", "rxjs": "~6.3.3", "sweetalert2": "^8.11.4", "tree-ngx": "^3.1.2", "tslib": "^1.9.0", "xlsx": "^0.15.1", "zone.js": "~0.8.26" }, "devDependencies": { "@angular-devkit/build-angular": "~0.13.0", "@angular/cli": "~7.3.8", "@angular/compiler-cli": "~7.2.0", "@angular/language-service": "~7.2.0", "@babel/core": "^7.7.2", "@babel/preset-env": "^7.7.1", "@types/jasmine": "~2.8.8", "@types/jasminewd2": "~2.0.3", "@types/node": "~8.9.4", "codelyzer": "~4.5.0", "jasmine-core": "~2.99.1", "jasmine-spec-reporter": "~4.2.1", "karma": "~4.0.0", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "~2.0.1", "karma-jasmine": "~1.1.2", "karma-jasmine-html-reporter": "^0.2.2", "protractor": "~5.4.0", "ts-node": "~7.0.0", "tslint": "~5.11.0", "typescript": "~3.2.2" } }

测试:

const shallow = (props = {}) => shallow(<ParagraphComponent {...props} />);

测试失败,并显示:

  

预期的模拟函数已被调用:             {“单位”:“ px”,“值”:123}           作为参数2,但它被称为             {“ unit”:“”,“ value”:“”}。

到底该如何调用该函数,但是即使我传递的是实际值,也使用空值?!

我尝试传递it('Should fire onChange', () => { const props = { context: context.paragraphStyle.style, onChange: jest.fn() }; const instance = shallow(props); const paragraphInput = instance.find('paragraphInput.fontsize'); paragraphInput.prop('onChange')(undefined, { unit: "px" value: '123' }); paragraphInput.prop('onBlur')(); // required to fire the onChange expect(props.onChange).toBeCalledWith('font.size', { unit: 'px', value: 123 }); }); ,尝试使用{ target: { value: 123 }},我尝试将值传递到act(),但是没有用。

0 个答案:

没有答案