Skip to content
Browse files

add more testcase

  • Loading branch information...
1 parent 611b777 commit 413bce0dfbac60d13659ebab50f68d65264a1930 @popomore committed Nov 5, 2012
Showing with 46 additions and 0 deletions.
  1. +1 −0 tests/runner.html
  2. +45 −0 tests/share-spec.js
View
1 tests/runner.html
@@ -11,6 +11,7 @@
<script>mocha.setup('bdd')</script>
<script src="../src/share.js"></script>
<script src="../src/parser.js"></script>
+ <script src="share-spec.js"></script>
<script src="parser-spec.js"></script>
<script>
if (window.mochaPhantomJS) {
View
45 tests/share-spec.js
@@ -0,0 +1,45 @@
+describe('Share.init', function() {
+ var expect = chai.expect;
+
+ it('should generate data-shareurl', function() {
+ var link = document.createElement('a');
+ link.id = 'example';
+ link.setAttribute('data-service', 'douban');
+ document.body.appendChild(link);
+
+ Share.init([document.getElementById('example')], {
+ title: '中文',
+ url: 'http://github.com?a=1&b=2'
+ });
+
+ expect(link.getAttribute('data-shareurl')).to.equal('http://shuo.douban.com/!service/share?name=%E4%B8%AD%E6%96%87&href=http%3A%2F%2Fgithub.com%3Fa%3D1%26b%3D2&image=');
+
+ document.body.removeChild(link);
+ });
+
+ it('should not throw exception with no param', function() {
+ function fn() {
+ Share.init();
+ }
+ expect(fn).to.not.throw();
+ });
+
+ it('should have prority in data-api', function() {
+ var link = document.createElement('a');
+ link.id = 'example';
+ link.setAttribute('data-service', 'douban');
+ link.setAttribute('data-title', 'test');
+ link.setAttribute('data-url', 'http://chuo.me');
+ document.body.appendChild(link);
+
+ Share.init([document.getElementById('example')], {
+ title: '中文',
+ url: 'http://github.com?a=1&b=2'
+ });
+
+ expect(link.getAttribute('data-shareurl')).to.equal('http://shuo.douban.com/!service/share?name=test&href=http%3A%2F%2Fchuo.me&image=');
+
+ document.body.removeChild(link);
+ });
+});
+

0 comments on commit 413bce0

Please sign in to comment.
Something went wrong with that request. Please try again.