I am trying to write unit test cases in truffle framework.I am able to write and execute them. However, whenever I have 2 or more test cases the control jumps from 1 test case to another.
For ex: In my given test script the order of execution (added print statements) are out of sync. I am new to javascript and promise. Please let me know what I am missing
Expected output :
Contract: B
✓ Case1
✓ Case2
2 passing (77ms)
In test case 1
In test case 1--->Result
In test case 2
In test case 2--->Result1
In test case 2--->Result2
In test case 2--->Result3
Actual Output :
Using network 'development'.
Contract: B
✓ Case1
✓ Case2
2 passing (77ms)
In test case 1
In test case 2
In test case 1--->Result
In test case 2--->Result1
In test case 2--->Result2
In test case 2--->Result3
Code attached :
// Load A and B contract
var A = artifacts.require("./A.sol");
var B = artifacts.require("./B.sol");
contract('B', function(accounts) {
it("Case1", function() {
A.deployed().then(function(instance) {
instance.create("Testing1","test1",10,1788825289);
return instance.getContentAddr.call();
}).then (function(results){
var contents = results;
sg = contents[0];
return null;
}).then(function() {
console.log("In test case 1");
return B.at(sg).supply(sg,{from:web3.eth.accounts[1],value:11000000000000000000});
}).then (function(result) {
console.log("In test case 1--->Result");
});
});
it("Case2", function() {
A.deployed().then(function(instance) {
instance.create("Testing1","test2",10,1788825289);
return instance.getContentAddr.call();
}).then (function(results){
var contents = results;
sg = contents[0];
console.log("In test case 2");
return sg;
}).then(function(instance) {
return B.at(instance).supply(instance,{from:web3.eth.accounts[0],value:5000000000000000000});
}).then(function(result) {
console.log("In test case 2--->Result1");
return sg;
}).then(function(instance) {
console.log("In test case 2--->Result2");
return B.at(instance).resupply(web3.eth.accounts[0],5000000000000000000,{from:web3.eth.accounts[0]});
}).then(function(result) {
console.log("In test case 2--->Result3");
});
});
});