diff --git a/core/modules/views/tests/js/test/base.js b/core/modules/views/tests/js/test/base.js new file mode 100644 index 0000000..33f6ec9 --- /dev/null +++ b/core/modules/views/tests/js/test/base.js @@ -0,0 +1,27 @@ +var chai = require('chai'); +var assert = chai.assert; +var sinon = require('sinon'); + +$ = sinon.stub(); +$.withArgs(sinon.match.any).returns(sinon.stub({on: function() {} })); + +var Drupal = {}; +Drupal.behaviors = {}; +document = null; +drupalSettings = {}; + +var execfile = require("execfile.js"); +var context = execfile("../../js/base.js", { jQuery: $, Drupal: Drupal, document: document, drupalSettings: drupalSettings}); + +describe('base', function() { + describe('parseQueryString', function() { + it('parse empty string', function() { + var result = context.Drupal.Views.parseQueryString(''); + assert.deepEqual({}, result); + }); + it('parse simple query string', function() { + var result = context.Drupal.Views.parseQueryString('foo=bar'); + assert.deepEqual({foo: 'bar'}, result); + }); + }); +}); diff --git a/core/scripts/run-js-tests.sh b/core/scripts/run-js-tests.sh new file mode 100755 index 0000000..916bffc --- /dev/null +++ b/core/scripts/run-js-tests.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +function HELP { + echo -e "Help for run-js-tests.sh"\\n + echo -e "Run core tests: core/scripts/run-js-tests.sh core/tests/js/test" + echo -e "Run specific modules: core/scripts/run-js-tests.sh core/modules/views/tests/js/test" + exit 1 +} + +NUMARGS=$# +if [ $NUMARGS -eq 0 ]; then + HELP +fi + +DRUPAL_ROOT=$(pwd) +export NODE_PATH=${NODE_PATH}:${DRUPAL_ROOT}/core/tests/js/node_modules:${DRUPAL_ROOT}/core/tests/js + +PARAMS=("$@") +PARAMS[0]=${DRUPAL_ROOT}/${PARAMS[0]} +cd ${PARAMS[0]}/../ + +if [ "$1" == "--help" ]; then + PARAMS=(--help) +fi + +# devtool --break ${DRUPAL_ROOT}/core/tests/js/node_modules/mocha/bin/mocha -qc -- ${PARAMS[@]} +${DRUPAL_ROOT}/core/tests/js/node_modules/mocha/bin/mocha ${PARAMS[@]} diff --git a/core/tests/js/test/states.js b/core/tests/js/test/states.js index cc873f8..335b41c 100644 --- a/core/tests/js/test/states.js +++ b/core/tests/js/test/states.js @@ -8,16 +8,18 @@ Drupal.behaviors = {}; document = null; $ = sinon.stub(); -$.withArgs(null).returns(sinon.stub({on: function() {} })); +$.withArgs(sinon.match.any).returns(sinon.stub({on: function() {} })); var context = execfile("../../misc/states.js", { jQuery: $, Drupal: Drupal, document: document}); describe('states', function() { describe('states.Dependent.comparisons.Function', function () { - var states = context.Drupal.states; - assert.isOk(states.Dependent.comparisons.Function(function(a) { - return a == 'hello'; - }, 'hello')); + it('it compares', function() { + var states = context.Drupal.states; + assert.isOk(states.Dependent.comparisons.Function(function(a) { + return a == 'hello'; + }, 'hello')); + }); }); });