Commit e0670e4c authored by Robert Knight's avatar Robert Knight

Convert mocking from proxyquire to mockable-imports

Convert proxyquire mocking of several CoffeeScript modules.
parent 6a9248a8
proxyquire = require('proxyquire')
Plugin = require('../../plugin') Plugin = require('../../plugin')
CrossFrame = null CrossFrame = require('../cross-frame')
describe 'CrossFrame', -> describe 'CrossFrame', ->
fakeDiscovery = null fakeDiscovery = null
...@@ -41,16 +39,16 @@ describe 'CrossFrame', -> ...@@ -41,16 +39,16 @@ describe 'CrossFrame', ->
proxyDiscovery = sandbox.stub().returns(fakeDiscovery) proxyDiscovery = sandbox.stub().returns(fakeDiscovery)
proxyBridge = sandbox.stub().returns(fakeBridge) proxyBridge = sandbox.stub().returns(fakeBridge)
CrossFrame = proxyquire('../cross-frame', { CrossFrame.$imports.$mock({
'../plugin': Plugin, '../plugin': Plugin,
'../annotation-sync': proxyAnnotationSync, '../annotation-sync': proxyAnnotationSync,
'../../shared/bridge': proxyBridge, '../../shared/bridge': proxyBridge,
'../../shared/discovery': proxyDiscovery '../../shared/discovery': proxyDiscovery
}) })
afterEach -> afterEach ->
sandbox.restore() sandbox.restore()
CrossFrame.$imports.$restore()
describe 'CrossFrame constructor', -> describe 'CrossFrame constructor', ->
it 'instantiates the Discovery component', -> it 'instantiates the Discovery component', ->
......
proxyquire = require('proxyquire') Host = require('../host')
Host = proxyquire('../host', {})
describe 'Host', -> describe 'Host', ->
sandbox = sinon.sandbox.create() sandbox = sinon.sandbox.create()
......
'use strict'; 'use strict';
const proxyquire = require('proxyquire');
const isLoaded = require('../../util/frame-util').isLoaded; const isLoaded = require('../../util/frame-util').isLoaded;
const FRAME_DEBOUNCE_WAIT = require('../../frame-observer').DEBOUNCE_WAIT + 10; const FRAME_DEBOUNCE_WAIT = require('../../frame-observer').DEBOUNCE_WAIT + 10;
const CrossFrame = require('../../plugin/cross-frame');
describe('CrossFrame multi-frame scenario', function() { describe('CrossFrame multi-frame scenario', function() {
let fakeAnnotationSync; let fakeAnnotationSync;
...@@ -30,7 +30,7 @@ describe('CrossFrame multi-frame scenario', function() { ...@@ -30,7 +30,7 @@ describe('CrossFrame multi-frame scenario', function() {
proxyAnnotationSync = sandbox.stub().returns(fakeAnnotationSync); proxyAnnotationSync = sandbox.stub().returns(fakeAnnotationSync);
proxyBridge = sandbox.stub().returns(fakeBridge); proxyBridge = sandbox.stub().returns(fakeBridge);
const CrossFrame = proxyquire('../../plugin/cross-frame', { CrossFrame.$imports.$mock({
'../annotation-sync': proxyAnnotationSync, '../annotation-sync': proxyAnnotationSync,
'../../shared/bridge': proxyBridge, '../../shared/bridge': proxyBridge,
}); });
...@@ -53,6 +53,8 @@ describe('CrossFrame multi-frame scenario', function() { ...@@ -53,6 +53,8 @@ describe('CrossFrame multi-frame scenario', function() {
sandbox.restore(); sandbox.restore();
crossFrame.destroy(); crossFrame.destroy();
container.parentNode.removeChild(container); container.parentNode.removeChild(container);
CrossFrame.$imports.$restore();
}); });
it('detects frames on page', function() { it('detects frames on page', function() {
......
events = require('../../shared/bridge-events') events = require('../../shared/bridge-events')
proxyquire = require('proxyquire') Sidebar = require('../sidebar')
rafStub = (fn) ->
fn()
Sidebar = proxyquire('../sidebar', { raf: rafStub })
DEFAULT_WIDTH = 350 DEFAULT_WIDTH = 350
DEFAULT_HEIGHT = 600 DEFAULT_HEIGHT = 600
...@@ -17,6 +12,14 @@ describe 'Sidebar', -> ...@@ -17,6 +12,14 @@ describe 'Sidebar', ->
fakeCrossFrame = null fakeCrossFrame = null
sidebarConfig = {pluginClasses: {}} sidebarConfig = {pluginClasses: {}}
before ->
rafStub = (fn) ->
fn()
Sidebar.$imports.$mock({ raf: rafStub })
after ->
Sidebar.$imports.$restore()
createSidebar = (config={}) -> createSidebar = (config={}) ->
config = Object.assign({}, sidebarConfig, config) config = Object.assign({}, sidebarConfig, config)
element = document.createElement('div') element = document.createElement('div')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment