Nidal
2 months ago
673
1
Testing

TDD (Given, When, Then) snippets for VSC

Posted 2 months ago by Nidal

I made this to help me write tests.

It's a snippet for the 3 comments used in the from scratch TDD episode.

It uses placeholders and some options for easy use.

I don't think it's too flexible at the moment as i haven't been introduced to too many testing cases. I might try to keep this post updated as i go.

The snippets:

"TDD Given" : {
        "prefix": "given",
        "body": [
            "$LINE_COMMENT GIVEN i am a {${1:User}}, whos is {${2:logged in}}.LARACASTS_SNIPPET_PLACEHOLDER"
        ],
        "description": "",
    },

    "TDD When" : {
        "prefix": "when",
        "body": [
            "$LINE_COMMENT WHEN i request the route {/${1:ROUTE}}, to {${2|create,read,update,delete|}} , while passing {${4:DATA}}.LARACASTS_SNIPPET_PLACEHOLDER"
        ],
        "description": "",
    },

    "TDD Then" : {
        "prefix": "then",
        "body": [
            "$LINE_COMMENT THEN there should be a new {${1:ENTITY}} row in the database table {${2:TABLE}}.LARACASTS_SNIPPET_PLACEHOLDER"
        ],
        "description": "",
    },

To use them in Visual Studio Code you do ctrl+shift+p and look for user snippets -> php -> and paste them in :)

Please sign in or create an account to participate in this conversation.