Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Elliott Marquez committed Jul 26, 2018
1 parent 94d0600 commit 99feacb
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 86 deletions.
6 changes: 3 additions & 3 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<script src="../../../wct-browser-legacy/browser.js"></script>
<script src="../node_modules/wct-browser-legacy/browser.js"></script>
</head>
<body>
<script>
WCT.loadSuites([
'prism-element.html?dom=shadow',
'prism-element.html?wc-shadydom=true&wc-ce=true'
'prism-element.html',
'prism-element.html?wc-shadydom=true&wc-ce=true',
]);
</script>
</body>
Expand Down
152 changes: 75 additions & 77 deletions test/prism-element.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
<meta charset="UTF-8">
<title>prism-element basic tests</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<script src="../../../@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
<script src="../../../wct-browser-legacy/browser.js"></script>
<script type="module" src="../prism-highlighter.js"></script>
<script type="module" src="./simple-container.js"></script>
<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
<script src="../node_modules/wct-browser-legacy/browser.js"></script>
</head>
<body>
<test-fixture id="simple">
Expand All @@ -39,109 +37,109 @@
</test-fixture>

<script type="module">
import '../prism-highlighter.js';
import './simple-container.js';
suite('<prism-highlighter>', function() {
var el;
import '../prism-highlighter.js';
import './simple-container.js';
suite('<prism-highlighter>', function() {
var el;

setup(function() {
sinon.spy(Prism, 'highlight');
el = fixture('simple');
});
setup(function() {
sinon.spy(Prism, 'highlight');
el = fixture('simple');
});

teardown(function() {
Prism.highlight.restore();
});
teardown(function() {
Prism.highlight.restore();
});

test('highlights on syntax-highlight event', function() {
var ev = {code: '<foo>', lang: 'markup'};
test('highlights on syntax-highlight event', function() {
var ev = {code: '<foo>', lang: 'markup'};

el.fire('syntax-highlight', ev);
el.fire('syntax-highlight', ev);

expect(Prism.highlight.calledWithExactly('<foo>', Prism.languages.markup))
.to.equal(true);
});
expect(Prism.highlight.calledWithExactly('<foo>', Prism.languages.markup))
.to.equal(true);
});

test('warns on invalid syntax-highlight event', function() {
var ev;
test('warns on invalid syntax-highlight event', function() {
var ev;

sinon.spy(console, 'warn');
sinon.spy(console, 'warn');

el.fire('syntax-highlight');
el.fire('syntax-highlight');

expect(console.warn.callCount).to.equal(1);
expect(console.warn.callCount).to.equal(1);

ev = {};
ev = {};

el.fire('syntax-highlight', ev);
el.fire('syntax-highlight', ev);

expect(console.warn.callCount).to.equal(2);
expect(ev.code).to.equal(undefined);
});
expect(console.warn.callCount).to.equal(2);
expect(ev.code).to.equal(undefined);
});

test('ignores repeated highlights', function() {
var ev = {code: '<foo>'};
test('ignores repeated highlights', function() {
var ev = {code: '<foo>'};

el = fixture('double-highlight');
el = fixture('double-highlight');

el.querySelector('#container-1').fire('syntax-highlight', ev);
el.querySelector('#container-1').fire('syntax-highlight', ev);

expect(Prism.highlight.callCount).to.equal(1);
});
expect(Prism.highlight.callCount).to.equal(1);
});

suite('applies simple lang detection if none specified', function() {
test('detects as markup if begins with tag', function() {
var ev = {code: '<foo>'};
suite('applies simple lang detection if none specified', function() {
test('detects as markup if begins with tag', function() {
var ev = {code: '<foo>'};

el.fire('syntax-highlight', ev);
el.fire('syntax-highlight', ev);

expect(Prism.highlight.calledWithExactly('<foo>', Prism.languages.markup))
.to.equal(true);
});
expect(Prism.highlight.calledWithExactly('<foo>', Prism.languages.markup))
.to.equal(true);
});

test('detects as javascript if no tag at start', function() {
var ev = {code: 'return;'};
test('detects as javascript if no tag at start', function() {
var ev = {code: 'return;'};

el.fire('syntax-highlight', ev);
el.fire('syntax-highlight', ev);

expect(Prism.highlight.calledWithExactly(
'return;', Prism.languages.javascript))
.to.equal(true);
});
});
expect(Prism.highlight.calledWithExactly(
'return;', Prism.languages.javascript))
.to.equal(true);
});
});

suite('detects language for abbreviated lang', function() {
test('detects js as javascript', function() {
var ev = {code: 'return;', lang: 'js'};
suite('detects language for abbreviated lang', function() {
test('detects js as javascript', function() {
var ev = {code: 'return;', lang: 'js'};

el.fire('syntax-highlight', ev);
el.fire('syntax-highlight', ev);

expect(Prism.highlight.calledWithExactly(
'return;', Prism.languages.javascript))
.to.equal(true);
});
expect(Prism.highlight.calledWithExactly(
'return;', Prism.languages.javascript))
.to.equal(true);
});

test('detects es as javascript', function() {
var ev = {code: 'return;', lang: 'es'};
test('detects es as javascript', function() {
var ev = {code: 'return;', lang: 'es'};

el.fire('syntax-highlight', ev);
el.fire('syntax-highlight', ev);

expect(Prism.highlight.calledWithExactly(
'return;', Prism.languages.javascript))
.to.equal(true);
});
expect(Prism.highlight.calledWithExactly(
'return;', Prism.languages.javascript))
.to.equal(true);
});

test('detects c as clike', function() {
var ev = {code: 'return;', lang: 'c'};
test('detects c as clike', function() {
var ev = {code: 'return;', lang: 'c'};

el.fire('syntax-highlight', ev);
el.fire('syntax-highlight', ev);

expect(
Prism.highlight.calledWithExactly('return;', Prism.languages.clike))
.to.equal(true);
});
});
});
</script>
expect(
Prism.highlight.calledWithExactly('return;', Prism.languages.clike))
.to.equal(true);
});
});
});
</script>
</body>
</html>
13 changes: 7 additions & 6 deletions test/simple-container.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/**
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
This code may only be used under the BSD style license found at
http://polymer.github.io/LICENSE.txt The complete set of authors may be found at
http://polymer.github.io/AUTHORS.txt The complete set of contributors may be
found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as
part of the polymer project is also subject to an additional IP rights grant
found at http://polymer.github.io/PATENTS.txt
*/
import '@polymer/polymer/polymer-legacy.js';

import { Polymer } from '@polymer/polymer/lib/legacy/polymer-fn.js';
import {Polymer} from '@polymer/polymer/lib/legacy/polymer-fn.js';
Polymer({is: 'simple-container'});

0 comments on commit 99feacb

Please sign in to comment.