Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

chore(ngMock): add they helper for testing multiple specs #10864

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions test/helpers/privateMocks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
'use strict';

function they(msg, vals, spec, specialState) {
var keyIsValue = isArray(vals);
forEach(vals, function(val, key) {
if (keyIsValue) {
key = val;
}
var m = msg.replace('$prop', key);
var method;
switch(specialState) {
case 'focus':
method = iit;
break;
case 'skip':
method = xit;
break;
default:
method = it;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about replacing this switch with something like:

var methods = {focus: iit, skip: xit, default: it};
var method = methods[specialState || 'default'];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

method(m, function() {
spec(val);
});
});
}

function tthey(msg, vals, spec) {
they(msg, vals, spec, 'focus');
}

function xthey(msg, vals, spec) {
they(msg, vals, spec, 'skip');
}

function createMockStyleSheet(doc, wind) {
doc = doc ? doc[0] : document;
wind = wind || window;
Expand Down
13 changes: 0 additions & 13 deletions test/ngMessages/messagesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,6 @@ describe('ngMessages', function() {
beforeEach(inject.strictDi());
beforeEach(module('ngMessages'));

function they(msg, vals, spec, focus) {
forEach(vals, function(val, key) {
var m = msg.replace('$prop', key);
(focus ? iit : it)(m, function() {
spec(val);
});
});
}

function tthey(msg, vals, spec) {
they(msg, vals, spec, true);
}

function s(str) {
return str.replace(/\s+/g,'');
}
Expand Down