Changing util.js to export an object
This allows the methods to be spied on in tests
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { customEvent } from 'src/js/util.js';
|
||||
import util from 'src/js/util.js';
|
||||
import Regexper from 'src/js/regexper.js';
|
||||
import Parser from 'src/js/parser/javascript.js';
|
||||
import Snap from 'snapsvg';
|
||||
@@ -25,7 +25,7 @@ describe('regexper.js', function() {
|
||||
describe('#keypressListener', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
this.event = customEvent('keypress');
|
||||
this.event = util.customEvent('keypress');
|
||||
spyOn(this.event, 'preventDefault');
|
||||
spyOn(this.regexper.form, 'dispatchEvent');
|
||||
});
|
||||
@@ -100,7 +100,7 @@ describe('regexper.js', function() {
|
||||
describe('#documentKeypressListener', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
this.event = customEvent('keyup');
|
||||
this.event = util.customEvent('keyup');
|
||||
this.regexper.runningParser = jasmine.createSpyObj('parser', ['cancel']);
|
||||
});
|
||||
|
||||
@@ -135,7 +135,7 @@ describe('regexper.js', function() {
|
||||
describe('#submitListener', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
this.event = customEvent('submit');
|
||||
this.event = util.customEvent('submit');
|
||||
spyOn(this.event, 'preventDefault');
|
||||
|
||||
this.regexper.field.value = 'example value';
|
||||
@@ -191,7 +191,7 @@ describe('regexper.js', function() {
|
||||
describe('#updatePercentage', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
this.event = customEvent('updateStatus', { percentage: 0.42 });
|
||||
this.event = util.customEvent('updateStatus', { percentage: 0.42 });
|
||||
});
|
||||
|
||||
it('sets the width of the progress bar', function() {
|
||||
|
||||
+6
-6
@@ -1,16 +1,16 @@
|
||||
import { customEvent, normalizeBBox, spaceHorizontally, spaceVertically } from 'src/js/util.js';
|
||||
import util from 'src/js/util.js';
|
||||
|
||||
describe('util.js', function() {
|
||||
|
||||
describe('customEvent', function() {
|
||||
|
||||
it('sets the event type', function() {
|
||||
var event = customEvent('example');
|
||||
var event = util.customEvent('example');
|
||||
expect(event.type).toEqual('example');
|
||||
});
|
||||
|
||||
it('sets the event detail', function() {
|
||||
var event = customEvent('example', 'detail');
|
||||
var event = util.customEvent('example', 'detail');
|
||||
expect(event.detail).toEqual('detail');
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ describe('util.js', function() {
|
||||
describe('normalizeBBox', function() {
|
||||
|
||||
it('defaults the anchor keys to values from the bbox', function() {
|
||||
expect(normalizeBBox({
|
||||
expect(util.normalizeBBox({
|
||||
x: 'bbox x',
|
||||
x2: 'bbox x2',
|
||||
cy: 'bbox cy',
|
||||
@@ -53,7 +53,7 @@ describe('util.js', function() {
|
||||
spyOn(items[1], 'transform').and.callThrough();
|
||||
spyOn(items[2], 'transform').and.callThrough();
|
||||
|
||||
spaceHorizontally(items, { padding: 5 });
|
||||
util.spaceHorizontally(items, { padding: 5 });
|
||||
|
||||
expect(items[0].transform).toHaveBeenCalledWith(Snap.matrix()
|
||||
.translate(0, 10));
|
||||
@@ -82,7 +82,7 @@ describe('util.js', function() {
|
||||
spyOn(items[1], 'transform').and.callThrough();
|
||||
spyOn(items[2], 'transform').and.callThrough();
|
||||
|
||||
spaceVertically(items, { padding: 5 });
|
||||
util.spaceVertically(items, { padding: 5 });
|
||||
|
||||
expect(items[0].transform).toHaveBeenCalledWith(Snap.matrix()
|
||||
.translate(10, 0));
|
||||
|
||||
Reference in New Issue
Block a user