Skip to content

Commit 566bdbf

Browse files
Ensure arguments are passed down to trigger (#381)
When we switched our `drop` implementation away from lodash, we accidentally stopped passing things like `step` and `previous` down to subsequent trigger calls. This fixes the `drop` call by ensuring `arguments` is now an array. Fixes #371
1 parent df2804e commit 566bdbf

File tree

5 files changed

+310
-297
lines changed

5 files changed

+310
-297
lines changed

babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = function(api) {
2828
]
2929
],
3030
plugins: [
31+
'rewire-exports',
3132
'transform-es2015-modules-commonjs'
3233
]
3334
}

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,18 @@
5353
"tippy.js": "^4.3.0"
5454
},
5555
"devDependencies": {
56-
"@babel/core": "^7.4.4",
56+
"@babel/core": "^7.4.5",
5757
"@babel/plugin-transform-object-assign": "^7.2.0",
58-
"@babel/preset-env": "^7.4.4",
58+
"@babel/preset-env": "^7.4.5",
5959
"autoprefixer": "^9.5.1",
6060
"babel-core": "^7.0.0-bridge.0",
6161
"babel-jest": "^24.7.1",
62+
"babel-plugin-rewire-exports": "^1.1.0",
6263
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
6364
"chai": "^4.2.0",
6465
"codeclimate-test-reporter": "^0.5.1",
6566
"cssnano": "^4.1.10",
66-
"cypress": "^3.2.0",
67+
"cypress": "^3.3.1",
6768
"del": "^4.1.1",
6869
"esdoc": "^1.1.0",
6970
"esdoc-ecmascript-proposal-plugin": "^1.0.0",
@@ -87,7 +88,7 @@
8788
"rollup-plugin-commonjs": "^9.3.4",
8889
"rollup-plugin-css-only": "^1.0.0",
8990
"rollup-plugin-eslint": "^6.0.0",
90-
"rollup-plugin-filesize": "^6.0.1",
91+
"rollup-plugin-filesize": "^6.1.0",
9192
"rollup-plugin-license": "^0.8.1",
9293
"rollup-plugin-multi-entry": "^2.1.0",
9394
"rollup-plugin-node-resolve": "^5.0.0",
@@ -96,7 +97,7 @@
9697
"rollup-plugin-terser": "^5.0.0",
9798
"rollup-plugin-visualizer": "^1.1.1",
9899
"sinon": "^7.3.2",
99-
"start-server-and-test": "^1.9.0",
100+
"start-server-and-test": "^1.9.1",
100101
"stylelint": "^10.0.1",
101102
"stylelint-config-ship-shape": "^0.5.2"
102103
},

src/js/evented.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class Evented {
3636

3737
trigger(event) {
3838
if (!isUndefined(this.bindings) && this.bindings[event]) {
39-
const args = drop(arguments);
39+
const args = drop(Array.prototype.slice.call(arguments));
4040

4141
this.bindings[event].forEach((binding, index) => {
4242
const { ctx, handler, once } = binding;

test/unit/tour.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Step } from '../../src/js/step.js';
55
import tippy from 'tippy.js';
66
import { defaults as tooltipDefaults } from '../../src/js/utils/tooltip-defaults';
77
import { spy } from 'sinon';
8+
import { drop, rewire$drop, restore } from '../../src/js/utils/general';
89

910
// since importing non UMD, needs assignment
1011
window.Shepherd = Shepherd;
@@ -379,6 +380,14 @@ describe('Tour | Top-Level Class', function() {
379380
});
380381

381382
describe('.show()', function() {
383+
let dropSpy;
384+
385+
beforeEach(() => {
386+
rewire$drop(dropSpy = spy(drop));
387+
});
388+
389+
afterEach(restore);
390+
382391
it('show short-circuits if next is not found', function() {
383392
let showFired = false;
384393
instance.start();
@@ -399,6 +408,15 @@ describe('Tour | Top-Level Class', function() {
399408
shouldShowStep = true;
400409
instance.next();
401410
expect(instance.getCurrentStep().id, 'step shown because `showOn` returns true').toBe('skipped-step');
411+
412+
// This spy checks that, when we call `trigger` with `show`, that we pass `arguments` down.
413+
const dropArguments = dropSpy.args[2][0];
414+
const dropReturnValue = dropSpy.returnValues[2][0];
415+
expect(dropArguments[0]).toBe('show');
416+
expect(dropArguments[1].previous).toBe(null);
417+
expect(dropArguments[1].step.id).toBe('test');
418+
expect(dropReturnValue.previous).toBe(null);
419+
expect(dropReturnValue.step.id).toBe('test');
402420
});
403421

404422
it(`sets the instance on \`Shepherd.activeTour\` if it's not already set`, function() {

0 commit comments

Comments
 (0)