Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.js"></script>
<script src="http://builds.emberjs.com.s3.amazonaws.com/tags/v1.0.0/ember.js"></script>
<link href="http://code.jquery.com/qunit/qunit-git.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <div id="qunit"></div>
  <div id="qunit-fixture"></div>
</body>
</html>
 
var App = Ember.Application.create();
var SomeComponent = Ember.Component.extend({
  template: Ember.Handlebars.compile('{{someAttr}}'),
  someAttr: 'foo value'
});
var component;
module('SomeComponent', {
  setup: function(){
    component = SomeComponent.create();
    Ember.run(function(){
      component.appendTo('#qunit-fixture');
    });
  },
  
  teardown: function(){
    Ember.run(function(){
      component.destroy();
      component = null;
    });
  }
});
test('Outputs the default value', function() {
  Ember.run(function() {
    component.set('someAttr', 'default value');
    stop();
    Em.run.schedule('afterRender',function(){
      start();
      var result = component.$().text().trim();
      equal(result, "default value", "it should render the default value");
    });
  });
});
test('Outputs a different attribute value on the component, when set and present in the template', function() {
  Ember.run(function() {
    component.set('someAttr', 'a non-default value');
    stop();
    Em.run.schedule('afterRender',function(){
      start();
      var result = component.$().text().trim();
      equal(result, "a non-default value", "it should render the default value");
    });
  });
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
kingpin2kpro
0viewers