# In DBT unit tests can you mock {{ this }} and use the given options to mock records?

**URL:** <https://discourse.getdbt.com/t/in-dbt-unit-tests-can-you-mock-this-and-use-the-given-options-to-mock-records/14082>\
**Category:** Help\
**Tags:** testing\
**Created:** [July 5, 2024, 8:36pm UTC](https://discourse.getdbt.com/t/in-dbt-unit-tests-can-you-mock-this-and-use-the-given-options-to-mock-records/14082 "2024-07-05T20:36:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmarcil](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@jmarcil](https://discourse.getdbt.com/u/jmarcil)\
**Post date:** [July 5, 2024, 8:36pm UTC](https://discourse.getdbt.com/t/in-dbt-unit-tests-can-you-mock-this-and-use-the-given-options-to-mock-records/14082/1 "2024-07-05T20:36:04Z")

</div>

From the documentation it’s not clear if we can mock reference to the model we are testing.

Example if my model is

```auto
select * from my_model     
{% if is_incremental() -%}
    and _current_dbt_refreshed_at > (select max(_parent_dbt_refreshed_at) from {{ this }})
    {%- endif %}

```

It’s not clear if we can use unit test given feature to mock reference to {{this}}

```yml
unit_tests:
  - name: incremental_logic_only_new
    model: my_cool_model
    overrides:
      macros:
        # unit test this model in "full refresh" mode
        is_incremental: true
    given:
      - input: this / my_cool_model
        rows:
          - {col1: test, col2: test2}

```

---

<div class="post-metadata">

**Author:** ![brunoszdl](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/brunoszdl/32/4113_2.png) [@brunoszdl](https://discourse.getdbt.com/u/brunoszdl)\
**Post date:** [July 5, 2024, 8:47pm UTC](https://discourse.getdbt.com/t/in-dbt-unit-tests-can-you-mock-this-and-use-the-given-options-to-mock-records/14082/2 "2024-07-05T20:47:37Z")

</div>

Actually you have an example in the docs [Unit tests | dbt Developer Hub](https://docs.getdbt.com/docs/build/unit-tests)

Here is the example:

```auto
- name: my_incremental_model_incremental_mode
    model: my_incremental_model
    overrides:
      macros:
        # unit test this model in "incremental" mode
        is_incremental: true 
    given:
      - input: ref('events')
        rows:
          - {event_id: 1, event_time: 2020-01-01}
          - {event_id: 2, event_time: 2020-01-02}
          - {event_id: 3, event_time: 2020-01-03}
      - input: this 
        # contents of current my_incremental_model
        rows:
          - {event_id: 1, event_time: 2020-01-01}
    expect:
      # what will be inserted/merged into my_incremental_model
      rows:
        - {event_id: 2, event_time: 2020-01-02}
        - {event_id: 3, event_time: 2020-01-03}

```
