What's the proper way to use `beforeeach` in a giv...
# testing
b
What's the proper way to use
beforeeach
in a given-when-then block in TestBox? It does not work like describe/it. I've tried it inside
story
and inside
given
and neither seem to do the trick.
Sample code:
Copy code
component extends = "tests.base.spec" {

	function run() {
		story( "we should be able to find preconnect domains from the included assets", function() {
			beforeEach(
				body: function( currentSpec, data ) {
					variables.service = getMockService(
						publicMethods: [
							"getPreconnectDomainsFromIncludedAssets"
						]
					);
				}
			);

			it( "should do a thing", function() {
				debug( variables.service ); // defined here
			} );

			given( "an included JS asset internal to the website", function() {
				debug(variables.service); // not defined here

				when( "getting the list of domains", function() {
					then( "there should be nothing found", function() {
					} );
				} );
			} );
		} );
	}

}
s
Ours are inside
describe()
which we use like you're using
story()
b
story()
calls
describe()
under the hood so I see them as essentially the same thing
s
Copy code
describe( "Division assignment and calculation API Endpoint", () => {
			beforeEach( function( currentSpec ) {
				setup();
				mockUserRequestObject( { 'isRegistrar' : true, 'userID' : createGUID() } );
			} );

			it( "Will reject a request to change a division from a user without permissions", ( t ) => {
				request.securityObj.setIsRegistrar( false );
          ... blah blah blah
It's doing what it's supposed to there
b
"Testbox supports the use of function names
given()
and
when()
in-place of
describe()
function calls. The
then()
function call is an alternative for
it()
function calls."
I can get it to work like that with a basic describe/it setup
It sounds like TestBox treats story, given, and when as fancy
describe()
blocks
2
a
It does, It just allows you to use "business friendly" language in your tests. The functionality is the same as the describe. So you do test that read as:
Copy code
given "I have a basket with 2 items"
  when "I check out"
    then "it should charge the value of the basket"
The assert goes in the 'then' in your code (like an
it
)