自动确认为前端测试对话与摩卡

这看起来像用茉莉花的方式来自动确认对话框:自动确认为前端测试对话与摩卡

https://coderwall.com/p/elevha/stubbing-out-confirm-dialogs-in-jasmine

,这将是:

spyOn(window, 'confirm').andReturn(true); 

但是我想不通出去如何做到与摩卡一样......任何人都知道?我想摩卡并没有提供一些预先捆绑好的间谍?

回答:

好了,所以我们使用兴农与摩卡,相当于调用就像这样:

sinon.stub(window, 'confirm').returns(true); 

我们使用的后续因缘配置加载兴农:

// Karma configuration 

// Generated on Wed Oct 18 2017 09:34:40 GMT-0700 (PDT)

'use strict';

var path = require('path');

// create angular values dynamically for every karma run

require('./scripts/karma-testing/render-angular-values.js');

// run Running a single test file from command line

//KARMA_SPECS="test/unit/pages/home/controller/home-controller.spec.js" karma start karma.config.local.js

function getSpecs(specList) {

if (specList) {

return specList.split(',')

} else {

return ['test/unit/**/**/*.spec.js']

}

}

////////////////////////////////////////////////////////////////////////////////

module.exports = function (config) {

var webDriverConfig = {

hostname: 'qsghub-nprd-lnx-01',

port: 8080

};

config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)

basePath: '',

// frameworks to use

// available frameworks: https://npmjs.org/browse/keyword/karma-adapter

frameworks: ['mocha', 'chai', 'sinon'],

// list of files/patterns to load in the browser

files: [

//cdn

'https://cdnjs.cloudflare.com/ajax/libs/async/2.1.5/async.min.js',

'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js',

'https://cdnjs.cloudflare.com/ajax/libs/node-uuid/1.4.7/uuid.js',

'https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.5.0/bluebird.js',

'https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js',

'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js',

'https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js',

'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.js',

'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular-animate.js',

'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular-route.js',

'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular-sanitize.js',

'https://cdnjs.cloudflare.com/ajax/libs/angular-mocks/1.6.1/angular-mocks.js',

// local

'./public/lib/angular-ui-router/release/angular-ui-router.js',

'./public/lib/ng-csv/build/ng-csv.js',

'./public/lib/angular-bootstrap/ui-bootstrap-tpls.js',

'./public/lib/angular-flash-alert/dist/angular-flash.min.js',

'./node_modules/karma-read-json/karma-read-json.js',

'./public/app.js',

'./public/karma-helpers/load-angular-values.js',

'./public/shared/**/*.js',

'./public/pages/**/*.js',

'./public/shared/html/**/*.html',

'./public/pages/**/view/**/*.html',

{pattern: './test/unit/mock-json/*.json', watched: true, served: true, included: false},

// './public/pages/home/controller/home.controller.js',

// './public/pages/home/services/**/*.js',

// './public/pages/home/specs/home-service.spec.js',

//process.env.CDT_KARMA_TEST_PATH || './test/unit/**/**/*.spec.js',

].concat(getSpecs(process.env.KARMA_SPECS)),

// list of files to exclude

exclude: [],

// preprocess matching files before serving them to the browser

// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor

preprocessors: {

'./public/shared/html/**/*.html':['ng-html2js'],

'./public/shared/js/filter/*.js': ['coverage'],

'./public/shared/js/services/*.js': ['coverage'],

'./public/shared/js/directive/*.js': ['coverage'],

'./public/shared/js/directive/**/*.js': ['coverage'],

'./public/pages/**/view/**/*.html':['ng-html2js'],

'./public/pages/**/**/*.js': ['coverage']

},

ngHtml2JsPreprocessor: {

// If your build process changes the path to your templates,

// use stripPrefix and prependPrefix to adjust it.

stripPrefix: 'public/',

// prependPrefix: 'public/',

// // the name of the Angular module to create

moduleName: "templates"

},

coverageReporter: {

type: 'lcov',

dir: 'reports',

subdir: 'coverage'

},

sonarQubeUnitReporter: {

sonarQubeVersion: '5.x',

outputFile: 'reports/gunit.xml',

useBrowserName: false

},

// test results reporter to use

// possible values: 'dots', 'progress'

// available reporters: https://npmjs.org/browse/keyword/karma-reporter

reporters: ['spec','coverage', 'sonarqubeUnit'],

// web server port

// host: 'localhost',

port: 9876,

// enable/disable colors in the output (reporters and logs)

colors: true,

// level of logging

// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG

logLevel: config.LOG_INFO,

// enable/disable watching file and executing tests whenever any file changes

autoWatch: true,

// start these browsers

// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher

// start these browser

browsers: ['ChromeHeadless'],

// process.env.USER === dftjenkins

plugins: [

// we don't need phantomjs, because --headless chrome removes the need for phantomjs

'karma-chrome-launcher',

'karma-jasmine',

'karma-junit-reporter',

'karma-chai',

'karma-mocha',

'karma-sinon',

'karma-spec-reporter',

'karma-read-json',

'karma-coverage',

'karma-sonarqube-unit-reporter',

'karma-ng-html2js-preprocessor',

'karma-webdriver-launcher'

],

// Continuous Integration mode

// if true, Karma captures browsers, runs the tests and exits

singleRun: true,

// Concurrency level

// how many browser should be started simultaneous

concurrency: 5

})

};

以上是 自动确认为前端测试对话与摩卡 的全部内容, 来源链接: utcz.com/qa/261152.html

回到顶部