Created
June 24, 2011 05:26
-
-
Save kriszyp/1044276 to your computer and use it in GitHub Desktop.
This is how I want to write structured documentation and unit tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is the module, the implementation, distinct from the specification/interface. */ | |
define([...deps...], function(){ | |
return function(options){ | |
... | |
}; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is the specification/interface for the module: the documentation, the tests, the types, etc. belong together */ | |
define(["my-widget", "assert"], function(MyWidget, assert){ | |
return { | |
title: "My Widget", // title and describe the module (my-widget) export | |
description: "This is a module that creates my special widget. Here is an example of using it: {test:instantation}", | |
parameters: [ // top level export is a function/constructor, so define the parameters | |
{ | |
name: "args", | |
type: "object", | |
descripton: "A hash of options to mix in to the widget" | |
} | |
], | |
returns: { // define the instances this constructor returns | |
methods: { // methods on the instances | |
show: { | |
description: "Shows the widget", | |
parameters: [ | |
{ | |
name: "z", | |
description: "Specifies the z index of the widget", | |
type: "number" | |
} | |
] | |
} | |
}, | |
properties: { // properties on the instances | |
delay: { | |
description: "How long to take to show the widget" | |
} | |
}, | |
events: { // specifies the events the instances emit | |
change: { | |
description: "This event fires when the value changes" | |
} | |
} | |
}, | |
tests: { // here are my unit tests | |
instantation: function(){ | |
var widget = new MyWidget(); | |
assert(widget.isCreated); | |
}, | |
destroy: function(){ | |
... | |
}, | |
... | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting ... I'm always on the fence between docs as "data" v. docs that you can open in your text editor and just read (or inline docs that you can just read as well).