Skip to content

Instantly share code, notes, and snippets.

@uhunkler
Created April 26, 2013 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uhunkler/5465885 to your computer and use it in GitHub Desktop.
Save uhunkler/5465885 to your computer and use it in GitHub Desktop.
test object - JSTalk Sketch
/**
* Test object for simple asserts
* test.assert( typeof 1 === 'number', '1 is a number' ); // add a test
* test.print( 'text' ); // add some text
* test.show(); // output all results
*/
var test = {
heap: [],
assert: function (value, desc) {
var result = value ? "--- pass: " : "xxx fail: ";
result += desc;
this.heap.push(result);
},
print: function (desc) {
this.heap.push(desc);
},
show: function () {
var s = '';
for(var t in this.heap) {
s += this.heap[ t ] + "\n";
}
print(s);
}
};
// Test some layer methods with the simple test object
// A text layer must be selected in Sketch
var layer = selection[0];
// feature detection
test.print( "\n" + '__feature detection:' );
test.assert( ('name' in layer), "text layer knows the 'name' method" );
test.assert( ('setName' in layer), "text layer knows the 'setName' method" );
test.assert( ('font' in layer), "text layer knows the 'font' method" );
test.assert( ('setFont' in layer), "text layer knows the 'setFont' method" );
test.assert( ('fontPostscriptName' in layer), "text layer knows the 'fontPostscriptName' method" );
test.assert( ('setFontPostscriptName' in layer), "text layer knows the 'setFontPostscriptName' method" );
test.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment